Linux Command Line – quick list

Linux Commands and examples – short list:
ls – list contents of a directory sudo – “substitute user” (grants administrator rights)

  • ex: ls -al – list all files with size and owner and group

sudo -i – login as superuser or admin or root
cd – change directory
clear – clear screen
chmod – change file access permissions
chown – change file and group ownership

  • ex: chown -v -R googlethem:googlethem *.* (changes owner and group of ALL files in current directory, not other directories, recursively and gives verbose output). note: Recursive chown-> use * instead of *.* to chown all files inside all directories truly recursive!
    cp – copy

du -h – size of directory, h for human readable kbytes
grep – search (used as a pipe most often)

  • ex: cat example.php | grep -i cookie

ifconfig – shows IP address and other info about all interfaces including ethernet and wireless (may need /sbin/ifconfig if you are not logged in as root)
mv – move
rm – remove
cat – concatenate files (dump to screen)

  • ex: cat example.php | grep -i cookie

free -m – show free memory. A more detailed command:

  • ex: cat /proc/meminfo

nano – basic text editor – my favorite linux text editor with menus and keyboard command reference while editing
vi – advanced text editor -difficult to use because it doesn’t have a standard keyboard command set or a menu
fdisk – partition table manipulator (fdisk for windows and linux are different, their commands are unique to each platform!)

  • ex: fdisk -l (list all drives)

df – disk free (remaining / used disk space) (df reports space used)
users – users currently logged in
useradd – add a user
usermod – modify existing user
uname – show kernel version, processor type, number of cores, system data (try uname -a)
mount – mount a file system, cd or removable drive
netstat -tpe (-t show only TCP connections, -p show PID/name, -e extra info)
nslookup domainname – Show DNS server IP and website IP (I leave off the @nameserver part)
dig domainname @nameserver – Show nameserver’s A record IP and TTL (time to live)
umount – un-mount a file system, cd or removable drive
top – show current running processes updates on the fly in the command window!
touch – create new, empty, file
reboot – reboot your system
shutdown – shutdown your system
passwd – change user password
ping – ping a network device or location

  • ex: ping google.com

nslookup: googlethem.com  – Show a website’s IP address.

  • ex: nslookup: googlethem.com ns1.speedydns.net – Show IP for a domain name by looking at a specific DNS server.

more – show output one screen at a time
exit – logout of the terminal
eject – eject a cdrom or removable device
tar cvzf foo.tgz cps100 will tar the directory cps100 (and its files/subdirectories) into a tar file named foo.tgz.

  • ex: To tar all .cc and .h files into a tar file named foo.tgz use:
    tar cvzf foo.tgz *.cc *.h

find . -iname ‘filetofind.htm’

  • ex: In Linux to create a playlist with all the *.mp3, *.wav, *.ogg and *.wma in the current folder (and all subfolders) use the command:
  • find . -iname ‘*’ -print | sed -n -E -e ‘s/.*mp3/&/p’ -e ‘s/.*wav/&/p’ -e ‘s/.*ogg/&/p’ -e ‘s/.*wma/&/p’ > playlist.m3u
  • or this one:
  • find . -iregex ‘.*.(mp3|wav|ogg|wma)’ -print > playlist.m3u

find / -size +10000k -print0 | xargs -0 ls -l  To find all files larger than 20Megs on a linux server.

find . -type f -size +50000k -exec ls -lh {} \; | awk ‘{ print $9 “: ” $5 }’
To find all files larger than 50 Megs on a lunix server.