Useful Linux Commands

This is a compilation of rather rare, useful Linux Commands asked for by users, that do not warrant for a full article.

  • How to mount remote folders using sshfs
  • sshfs example.com:/stuff /media/music
    (unmount “fusermount -u /media/music”)

  • How to scan for wireless networks
  • iwlist eth1 scanning (replace eth1 with your interface)

  • How to backup mysql databaseĀ and compress backup file
  • mysqldump -ppassword -uuser -phost database_name | gzip > backup_name.sql.gz

  • How to check for disk space
  • df -h

  • How to display connection counts by ip address
  • netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -nr

  • How to mount a network share
  • sudo mount -t smbfs //san/ics /mnt/ics -o username=user,password=pass

  • How to find files modified recently or at a certain date
  • find . -mtime -1
    (find all files in the current directory and subdirectories, modified within the last 24 hours)
    find ~ -mmin -90
    (find all files in the home directory, modified within the past 90 minutes)
    find ~ -type f -mmin -90 | xargs ls -l
    (same as above, but with extended output information)

  • How to find text within files and display file names only
  • find . | xargs grep ‘string’ -sl
    (-s is for summary and won’t display warning messages, -l is for list, so we get just the filename)

  • How to retrieve OS version and Kernel info
  • uname -a print all information
    uname -r print kernel release
    uname -v print kernel version and info

  • How to delete all hidden .svn files and folders
  • find . -name .svn -print0 | xargs -0 rm -rf

  • MySQL repair, check and optimize all tables on all databases running on a server
  • mysqlcheck -u root -p password –auto-repair –check –optimize –all-databases

  • How to show line numbers in vi / vim editor
  • :set number or
    :set nu

  • MySQL – Select records in one table not found in the other
  • select * from table1 t1 left join table2 t2 on t1.id = t2.id where t2.id is null

  • Refresh Locate Database on Mac OS
  • sudo /usr/libexec/locate.updatedb

  • Display certain lines only of a large file (12000 thru 12002 in this case)
  • sed -n ’12000,12002p’ file_name

  • Delete all .svn files within project directory
  • rm -rf `find . -type d -name .svn`

  • Tar and gzip all .jpg files that do not contain “thumbnail” in their filename
  • tar czvf img_0.tar.gz `find 0 -name ‘*[!thumbnail]*.jpg’`

If you know some exotic but useful unix commands, we’d be happy to add them. Simply drop us a line: submit@itecsoftware.com