
the big bash commands list….
Dezember 5, 2007Yes, this is my first attempt of creating a list of useful, everyday bash commands - as I find myself constantly in the situation looking for a specific bash command. If you’re unlucky, googleing the right command (especially if you don’t know what it’s called) can cost you several minutes if not hours.
So this will save me and hopefully you as well, the next time plenty of time. If you think there’s an important command still missing, which is more than likely, feel free to leave a comment with the command and a short explanation what it does.
Very special thanks to Bernd for the idea and his input! Thank you!
Basics:
cp test.txt /home/user/Desktop copies a txt file called test to the user’s Desktop
mv /home/test.txt /home/user/Desktop/ moves a txt file called test from the user’s home directory to the Desktop
sudo chmod -R 755 * changes the user rights recursively for the owner to read, write and execute - for group and world to read and execute. (this command requires root rights «sudo»)
sudo chmod -R u+w /home/user/data changes the user rights for the owner recursively to write and read of the directory /home/user/data
echo $USER prints the currently being used user name
sudo chown -R $USER.users ~/.kde/share/apps/kmail/mail changes the user ownership of the directory ~/.kde/share/apps/kmail/mail to the currently being used user name
ls -la ~/.kde/share/apps/ lists the content of a directory e.g ~/kde/share/apps/
ls | wc -l counts the files in a directory
cp test.txt{.bkp} copies text.txt to text.txt.bkp (creates a backup)
uname -a or uname -a | awk '{print $3}' lists your current kernel version number (awk ‘{print $3} prints only the kernel version, without its description)
Going deep:
perl -pi.bak -e 's/search/replace/' *.php replaces in all .php files the word “search” with “replace” and creates a backup file .bak e.g. index.php to index.php.bak
grep --color ; displays the search result in colour
grep -r searches /home/ searches recursively in /home/
pgrep firefox displays the process ID number of firefox or any application. useful to «kill» a process
sudo kill -9 pid pid = processID number ….. kill -9 kills the process (requires root rights)
sudo /etc/init.d/networking restart restarts the networking service
Mounting:
sudo mkdir hda1 creates a directory called “hda1″
sudo mount /dev/hda1 /mnt/hda1 mounts the harddisk hda1 into the directory /mnt/hda1
sudo umount /dev/sdb5 unmounts a device «sdb5» (in this case usb device)
sudo mount -t ntfs-3g /dev/hda5 /mnt/windows -o locale=de_DE.utf8 mounts a NTFS formatted harddisk read and writeable into /mnt/windows (this implies that the packages «ntfs-3g» & «ntfs-config» are installed)
sudo mount -t vfat /dev/hda1 /mnt/windows_c mounts a FAT formatted harddisk read and writeable into /mnt/windows_c
sudo blkid shows UUID number of a device
mount lists mounted devices
lsusb lists usb devices
sudo fdisk -l lists all mounted and unmounted harddisks or partitions
fuser -v /mount/point displays why a device can’t be unmounted and which process/user uses the device
Misc:
update-alternatives --config editor let’s you change the standard terminal editor (e.g from vim to nano)
ls -la /etc/alternatives/javac lists all java compilers
java -version displays the currently installed java version
msgfmt test.po -o test.mo compiles a language translation file (po) into a binary .mo file …. -o stands for output
sudo aptitude install language-pack-gnome-de installs a package from a repository (e.g. german gnome language pack)
sudo aptitude install tree installs a package called «tree»
tree -d -i (-i removes the 'tree') lists directories and subdirectories…
tree -d -i > dir.txt lists directories and subdirectories and saves the content into dir.txt
aptitude show ktorrent shows information on ktorrent and lists where it’s available (which repository)
MPLAYER:
mplayer -dumpstream "mms://a1505.v16544e.c16544.g.vm.akamaistream.net/7/1505/16544/v001/roomediaco1.download.akamai.com/16544/wm.roomedia/streamingVX/17056/1386/laptop_300.wmv?clipId=1386_computing_0030&channel=Netevents+TV&category=netevents+tv&site=vnudotnet%2fcomputing" -dumpfile laptop.wmv downloads a stream and saves it as «laptop.wmv»
This is a very good idea. Thank you very much. I don’t have the capacity to remember these or I lack the courage to even try, I find myself needing to google these hints, ad nausium. I keep jewels like these you are sharing here at my del.icio.us/enotes9/bash (or ~/urpmi)
If you or any of your readers are GNOMEies, a very useful one is in my stash if you follow my “website” link in this comment