ItecSoftware Logo

Useful Linux Terminal Commands

Written by Peter Gilg on - like this:
Linux terminal

This is a compilation of most of my past searches for linux terminal commands, starting years back and I kept track of them here for easy retrieval. Since some of them are rather rare, useful Linux Terminal Commands, also often asked for by users, I decided to just publish them here.

The list may grow longer over time and if you got some nice ones that is of general interest, please let me know and I’m happy to add them.

How to mount remote folders using sshfs

sshfs /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

print all information

uname -a

print kernel release

uname -r

print kernel version and info

uname -v

How to delete all hidden .svn files and folders

find . -name .svn -print0 | xargs -0 rm -rf

Check and optimize all tables on all databases using MySQL repair

mysqlcheck -u root -p password --auto-repair --check --optimize --all-databases

How to show line numbers in vi / vim editor

:set number

:set nu

MySQL – Select records in one table not found in the other

select * from table1 t1 left join table2 t2 on = where 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'`

How to delete lines matching a text pattern inside multiple files

sed -i '/pattern to match/d' ./infile

Note: -i modifies the file in-place. If data loss is a concern, use a redirect ( infile > outfile) and create a backup file.

How to replace text (search/replace) inside multiple files

perl -p -i -e 's/SEARCH/REPLACE/gi' ./*.html

If you know some exotic but useful unix commands, we’d be happy to add them. Simply drop us a comment below.

Listed in Linux, Shell Scripting

Tags: Linux, shell, terminal, Unix

Leave a Reply

Your email address will not be published. Required fields are marked *