Most commands below are run from the shell in a terminal (e.g. xterm, uxterm, urxvt)
urxvt supports tabbing, transparent background & font size resizing - it's definitely one of the very best terminals
Moving around
pwd path work directory - shows where you are cd name_of_dir/ move 1 directory down cd ../ move 1 directory up cd ../../ move 2 directories up ls list short / ls -a list all ...
Listing
ls -sh list size human ls -shR list size human recursively ls -l list long (i.e. with details) ls -rt list sort by time showing the most recent at the end
Build a text file with tree of hard drive contents (e.g. CD bup)
ls -shR | cat >> /home/user_name/contents_of_cdr.txt find $HOME -print > contents.txt find /home/user/* -type f -exec md5sum {} \;>> /home/user/checksums_home_user.md5 (time consuming but great for backups)
Build a text file with tree under Windows
dir e:\some_directory /S > e:\some_directory\contents_of_directory.txt
Check sizes used & available
df -h disk full human [how much room available] du -sh * disk use human [space used by all files in current directory]
Editing directories & files
mkdir xyz make directory xyz mkdir -p dir/subdir/subsubdir (-p = parents) rmdir xyz remove directory xyz [only possible if empty] rm -R dir remove directory and contents (recursively) rm -Rf dir force remove directory and contents
remove
rm file remove file rm *.jpg remove any file ending with .jpg
copy
cp file filebis copy file1 to file2 cp *.jpg another_sub_directory/ copy any file ending with .jpg to a sub-director cp *.jpg ../another_directory/ copy any file ending with .jpg to a higher director cp file1 /mnt/floppy/ cp file1 /media/usbdisk/
move and / or rename
mv file_old_name file_new_name mv file_old_name another_sub_directory/ mv file_old_name ../another_directory/ mv file_old_name ../another_directory/file_new_name
rename many files at a time
rename "s/old_keyword/new_keyword/" *.jpg rename "s/old_kwd|old_keyword/new_keyword/" *.jpg
convert all uppercase file names to lowercase
rename 'y/A-Z/a-z/' *
remove all blank space in file names
rename "s/ *//g" *.ogg
convert Dos file.txt to Unix file.txt
tr -d '\r' < input_file_dos.txt > output_file_unix.txt
convert Unix file.txt to Dos file.txt
sed 's/$'"/`echo \\\r`/" input_file_unix.txt > output_file_dos.txt
changing character encoding
typical encoding of French document [encoded usually with latin 1]
iconv -c --from-code=ISO_8859-15 --to-code=UTF-8 -o text_utf8.txt text_latin1.txttypical encoding of Polish document [encoded usually by M$ word]
iconv -c --from-code=WINDOWS-1250 --to-code=UTF-8 -o text_utf8.txt orig_1250.txt iconv -c --from-code=ISO8859-2 --to-code=UTF-8 -o text_utf8.txt orig_latin2.txt iconv -c --from-code=ISO8859-16 --to-code=UTF-8 -o text_utf8.txt orig_central_european_languages.txttypical encoding of Russian document [encoded usually by M$ word]
iconv -c --from-code=WINDOWS-1251 --to-code=UTF-8 -o document_utf8.txt default_windows_document_using_cyrillic.txt iconv -c --from-code=ISO8859-5 --to-code=UTF-8 -o text_utf8.txt orig_cyrillic.txt
display contents
cat file | less (to view contents - press v to enter vi - press q to quit) cat file 2 >> file1 adds file2 at the end of file1 cat file1 file2 > file 3 pastes file1 & file2 into file3 cat > new_file + press CTRL + D creates new_file echo "test" > test.txt (writes test to new file test.txt) head file.txt displays only first few lines of a file tail file.txt displays only last few lines of a file
copy physical image of a DVD media
dd if=/dev/sr0 of=/home/user/documents/film.iso bs=2048 xine dvd:///home/user/documents/film.iso
Archiving
tar cf new_file_or_directory.tar old_file_or_directory gzip -9 new_file_or_directory.tar
Extracting archives
gunzip file.tar.gz tar xf file.tar
Finding a file recursively
find . -name *keyword*.* check recursively all directories find /home/user/documents/* -name *keywords.pdf check recursively chosen directories
Finding keywords (i.e. regular expressions)
without opening files (hence only 'visiting')
grep -i keyword *.txt | less (ignore case) grep -A 6 name_telephone contacts.ldiff (+ 6 lines After occurence) grep -i -c 'late' agenda.csv to count number of occurrences (i.e. how many times was late...) grep -i 'Jacques\|Jack' contacts.txt to match either Jacques or Jack grep -i '2008' calendar.cal | grep -i -c 'skiing' to count number of times went skiing in 2008
Change mode
chmod 755 file
Change owner
chown -R user file_or_directory change ownership of file or directory & contents recursively chown -R user:user * change ownership (owner & group)
Selection of vi commands
:edit . explorer plugin :vi ~/ explore from home :vsplit :%substitute/old/new/gc :%s % on all lines substitute from / to / g - global (ie all occurrences) / c - confirm before substitute u undo . repeat j join broken sentences (followed by gq) ctrl+p auto-complete :r file reads contents of file :r!date reads from shell date :!bash cmd executes shell :n next (eg. :wn => writes & closes current, shows next) :N previous
Selection of Debian commands
apt-get update updates repositories where new software can be found (and not the system) apt-cache search xyz checks if software is available apt-get install software apt-get remove software apt-get upgrade use w/ care (will upgrade to latest version) dpkg -i install package.deb dpkg-reconfigure software dialogue setup of software only base-config drastic from scratch like config
Selection of rpm commands (red hat, mandriva, suze...)
urpmi rpm -qa | less query all (installed rpms) rpm -qi file.rpm query info (details) rpm file.rpm -test rpm -U file.rpm upgrade rpm -U -force -nodeps file.rpm rpm -e file.rpm erase rpm -ta file.tar.gz to build file.rpm
Selection of misc favourite commands
xterm -bg white -fg black to have a white xterm xterm -rv reverse video uxterm displays utf8 characters (Polish, Russian...) setxkbmap us / ru / pl / ca to change character mapping of keys nice -n19 kino to run rendering work in the background mount -t udf /dev/cdrw /media/cdrom to mount a dvd written in VR mode by a standalone DVD player umount -l /media/cdrom eject /media/cdrom wc -l (lines) -w (words) -c (bytes) word count ispell *.txt (-d dictionary) (-H html) ispell (enter) strange_word aspell -d french -c file_with_word_needing_checking dict -d fd-fra-eng essai dict -d fd-eng-fra attempt dict unknown_word will spit out all translations from all installed dictionaries
Finding more about hardware
useful when installing a new system and some features (eg. sound) don't seem to work
cat /proc/cpuinfo shows what processor the computer is using (and how fast) dmesg info from boot dmesg | grep hd to find where a hard disk is mounted (hda, sda...) hdparm -t /dev/hda1 to find speed of drive (old 20GB disk -> 16.29Mb vs. 100GB Seagate with 8Mb cache -> 44.63Mb/sec!) lspci lists pci on motherboard (eg. vga, multimedia audio controller, modem...)
Querying system in case of troubleshooting
dmesg | grep keyword tail /var/log/messages locale to get info on local settings whereis to find where (and if) software is installed cat /etc/group to see if recently-added user belongs to audio group adduser name audio to add a new user to the audio group (or else has no sound)
Shortcuts in case of crash
(from soft to harsh...)
ps -e | grep faulty_program shows # faulty_program (which is not always visible with top) top list running processes: k (kill) input # to end a crashed software q (quit) killall faulty_program will force ending in the same way as top ctrl + alt + backspace will force ending current window manager's session ctrl + alt + F[1-9] switch from GUI to terminal access only alt+sys+s sync partitions write & save all open files close all alt+sys+u umount then mount read-only all partitions alt+sys+b reboot now (same as triggering the reset button!)
Internet related
running with a modem
pppconfig great to get ppp setup pon to connect to the internet poff to disconnect from the internetrunning with a modem - alternative
kppp ifup ppp0 OR ifdown ppp0running w/ adsl & networking
ifconfig to find ip address given by server & bound to by dhcp /etc/init.d/networking stop | start | restart in case of cable disconnected
changing size of images with convert
convert is part of the tremendous ImageMagick suite of tools
convert -resize 15% copy_of_original_pix.jpg to reduce size of image for html photo gallery convert -geometry x30 original.jpg new.jpg to reduce size of image for html icon (maintains aspect ratio) convert -geometry 30x30 original.jpg new.jpg (changes aspect ratio) convert -geometry x576 original.png new.png to reduce size of screen shot *.jpg for import to Cinelerra (maintains aspect ratio) man convert to get a list of flags (options) available