www.LinuxHowtos.org
This is a list of some handy/common things you can do on the command line in Linux.Commands
lynx -dump -width=999 http://www.linuxhowtos.org/Misc/commandline.htm >cmd.txtMake a text copy of this page
apropos wordshow commands pertinent to word
which commandshow full path name of command
time commandsee how long a command takes
nice commandrun a low priority command
renice 19 -p $$make shell (script) low priority. Useful for non interactive tasks
look prefixquickly search dictionary
grep --color word /usr/share/dict/wordshighlight occurances of words in dictionary
gpg -c fileencrypt file
gpg file.gpgdecrypt file
echo 'wget url' | at 01:00download url at 1AM to current dir
echo "mail -s 'get the train' you@yourdomain < /dev/null" | at 17:45email reminder
watch -n1 'cat /proc/interrupts'watch changeable data continuously
alias hd='od -Ax -tx1z -v'handy hexdump. (usage e.g.: hd /proc/self/cmdline | less)
disc space
ls /usr/bin | pr -T9 -W$COLUMNSprint in 9 columns to width of terminal
touch -c -t 0304050607 fileset file timestamp (YYMMDDhhmm)
pstree -hlpshow process hierarchy
lsof /dir/fileshow process using file
ls -lSrshow files, biggest last
du -sh file dirshow disk usage of file and dir. See also dutop
df -hfree disk space
df -ifree inodes
fdisk -lshow disks partitions sizes (run as root)
rpm -q -a --queryformat '%10{SIZE} %{NAME}' | sort -k1,1nlist all packages by size
Dir navigation
cd -go to previous directory
cd ~go to home directory
(cd dir && command)go to dir, execute command and return to current dir
pushd .put current dir on stack so you can popd back to it
CDs
gzip < /dev/cdrom > cdrom.iso.gzsave copy of data cdrom
mkisofs -r dir | gzip > cdrom.iso.gzcreate cdrom image from directory
mount -oloop cdrom.iso /mnt/dirmount the cdrom image at /mnt/dir (for browsing)
gzip -dc cdrom.iso.gz | cdrecord dev=/dev/cdrom -burn cdrom image (use dev=ATAPI -scanbus to confirm dev)
cdparanoia -Brip audio tracks from CD to wav files in current dir
cdrecord dev=/dev/cdrom -audio *.wavmake audio CD from all wavs in current dir
oggenc --tracknum='track' track.cdda.wav -o 'track.ogg'make ogg file from wav file
archives
tar c dir/ | bzip2 > dir.tar.bz2make archive of dir/
bzip2 -dc dir.tar.bz2 | tar xextract archive (use gzip instead of bzip2 for tar.gz files)
tar c dir/ | gzip | gpg -c | ssh user@remote 'dd of=dir.tar.gz.gpg'make encrypted archive of dir/ on remote machine
find dir/ -name '*.txt' | tar c --files-from=- | bzip2 > dir_png.tar.bz2make archive of subset of dir/ and below
find dir/ -name '*.txt' | xargs cp --target-directory=dir_png/ --parentsmake copy of subset of dir/ and below
( tar c /dir/to/copy ) | ( cd /where/to/ && tar x )copy (with permissions) copy/ dir to /where/to/ dir
( cd /dir/to/copy && tar c . ) | ( cd /where/to/ && tar x )copy (with permissions) contents of copy/ dir to /where/to/ dir
( tar c /dir/to/copy ) | ssh -C user@remote 'cd /where/to/ && tar x'copy (with permissions) copy/ dir to remote:/where/to/ dir
dd bs=1M if=/dev/hda | gzip | ssh user@remote 'dd of=hda.gz'backup harddisk to remote machine
rsync (Use the --dry-run option for testing)
rsync -P rsync://rsync.server.com/path/to/file fileOnly get diffs. Do multiple times for troublesome downloads
rsync --bwlimit=1000 fromfile tofileLocally copy with rate limit. It's like nice for I/O
rsync -az -e ssh --delete ~/public_html/ remote.com:'~/public_html'Mirror web site (using compressed rsync over encrypted ssh)
rsync -auz -e ssh remote:/dir/ . && rsync -auz -e ssh . remote:/dir/Synchronize current directory with remote one
file searching
alias l='ls -l --color=auto'quick dir listing
ls -lrtlist files by date. See also newest
find -name '*.[ch]' | xargs grep -E 'search string'search *.c and *.h for 'search string' in this dir and below
find -type f -print0 | xargs -r0 grep -E 'search string'search all regular files for 'search string' in this dir and below
find -type f -maxdepth 1 | xargs grep -E 'search string'search all regular files for 'search string' in this dir
find -type f ! -perm -444find files not readable by all (useful for web site)
find -type d ! -perm -111find dirs not accessible by all (useful for web site)
locate -r 'file[^/]*.txt'search cached index for names. This re is like glob *file*.txt
Networking
(Note ifconfig, route, mii-tool, nslookup commands are obsolete)ip link showlist interfaces
ethtool interfacelist interface status
ip link set dev eth0 name wanrename eth0 to wan
ip addr add 1.2.3.4/24 brd + dev eth0add ip and mask(255.255.255.0)
ip link set dev interface upbring interface up (or down)
ip route add default via 1.2.3.254set default gateway to 1.2.3.254
host google.comlookup ip address for name or vice versa
netstat -lp --inetlist internet services on a system
netstat -p --inetlist active connections to/from system
echo 'message' | smbclient -M netbiosnameSend popup to windows machine (off by default as of XP sp2)
Math
echo '(1 + sqrt(5))/2' | bc -lquick math
echo 'obase=16; ibase=10; 123' | bcbase conversion (decimal to hex)
echo 'pad=20; min=64; (100*10^6)/((pad+min)*8)' | bcMore complex (integer) e.g. This shows max FastE packet rate
echo 'pad=20; min=64; print (100E6)/((pad+min)*8)' | pythonpython handles scientific notation
echo 'pad=20; plot [64:1518] (100*10**6)/((pad+x)*8)' | gnuplot -persistPlot FastE packet rate vs packet size
text manipulation
(note these use stdin and stdout, so if you want to edit files, append < oldfile > newfile)sed 's/string1/string2/g'replace string1 with string2
sed '/ *#/d; /^ *$/d'remove comments and blank lines
sed ':a; /\$/N; s/\//; ta'concatenate lines with trailing
sed 's/[ ]*$//'remove trailing spaces from lines
sed 's/([\`\"$\\])/\1/g'backslashify shell metacharacters active within double-quotes
sort file1 file1 file2 | uniq -ushow lines in file2 not in file1
echo 'Test' | tr '[:lower:]' '[:upper:]'case conversion
tr -dc '[:print:]' < /dev/urandomfilter non printable characters
grep 'processor' /proc/cpuinfo | wc -lcount lines
Calendar
cal -3display a calendar
date --date='25 Dec' +%Awhat day does xmas fall on, this year
date --date '1970-01-01 UTC 1097781420 seconds'convert number of seconds since the epoch to a date
TZ=':America/Los_Angeles' dateWhat time is it on West coast of US (use tzselect to find TZ)
locales
printf "%'d" 1234print number with thousands grouping appropriate to locale
echo "I live in `locale territory`"extract info from locale database
locale | cut -d= -f1 | xargs locale -kc | lesslist fields in locale database
LANG=ga_IE locale int_prefixlookup locale info for specific country. See also ccodes
recode
(Obsoletes iconv, dos2unix, unix2dos)recode -l | lessshow available conversions (aliases on each line)
recode windows-1252.. file_to_change.txtwindows "ansi" to local charset (auto does CRLF conversion)
recode utf-8/CRLF.. file_to_change.txtwindows utf8 to local charset
recode iso-8859-15..utf8 file_to_change.txtlatin9 (western europe) to utf8
recode ../b64 < file.txt > file.b64Base64 encode
recode ..HTML < file.txt > file.htmltext to HTML
recode -lf windows-1252show table of characters
echo -n 0xA4 | recode latin-9/x1..dumpshow what the character is in charmap
echo -n 0x20AC | recode ucs-2/x2..1252/xshow windows-1252 encoding
echo -n 0x20AC | recode ucs-2/x2..utf-8/xshow utf-8 encoding
interactive
mcpowerful filemanager that can browse rpm, tar, ftp, ssh, ...
screenvirtual terminals with detach capability, ...
lynxweb browser
gnuplotinteractive/scriptable graphing
octavematlab like environment
From http://www.iol.ie/~padraiga/cmdline.html
rate this article:
current rating: average rating: 1.2 (65 votes) (1=very good 6=terrible)
Your rating:
back