Linux Cheatsheet / Commonly Used Commands

Posted by: scoopseven 13 years ago

These are some Linux commands that I find myself searching for on a consistent basis.  These commands are used primarily on Arch Linux distros.

Find all files modified within a a certain time period on linux (eg. last 90 minutes)
find /path/of/directory/ -mmin -90

Get a count of files in all directories
for dir in $( find . -type d -print ); do files=$( find $dir -maxdepth 1 -type f | wc -l ); echo "$dir,$files"; done > /root/filelist.txt

Grep a directory for a string
grep -r -i somestring /srv/jb/deploy/mediapost.war

Find out who/where processes started from
netstat -anp | sort -u
also: tcpdump port 80 or tcpdump not port 25 is useful for current connections

Find files larger than 25M
find / -type f -size +25M -exec ls -lh {} \;

Size of a directory:
du -sL <directoryname>

Add a user:
adduser bendover

Add existing user to an existing group:
usermod -a -G ftp tony

get all users on a server:
awk -F: '{print $1}' /etc/passwd

SCP:
scp root@host:/var/filename.gz /var
scp /var/filename.sql.gz root@host:/var/filename.sql.gz
scp /var/filename.sql root@host:/var/filename.sql

Remove all files in current directory with find:
find -name 'filename-*' -exec rm {} \;

Gzip entire directory:
tar -zcvf /var/filename.tar.gz /folder
tar -zcvf /var/filename.tar.gz folder

If you wish to restore your archive then you need to use following command (it will extract all files in current directory):
$ tar -zxvf /var/filename.tar.gz

chown symbolic link
chown -h myuser:mygroup mysymbolic

link django admin media to be served on a site
ln -s /usr/lib/python2.6/site-packages/django/contrib/admin/media /srv/yoursite/admin-media

Currently unrated


Recent Tweets

Recent Posts

Archive

2013
2012
2011
2010
2009
2008
2007
2006

Categories

Authors

Feeds

RSS / Atom