Useful Linux Commands and typical examples
Site Navigation:

 
 

Useful Linux Commands and typical examples

Author:  Christophe Gevrey
Updated: [udate]

AreaCommandDescription and/or Example
daemonskill -9 PIDnumberKills the process PIDnumber that we want to (it stops running) kill -HUP PIDnumbe does the same. Kill -STOP PIDnumber Stopis until a new command the NumberPID process. Kill -CONT PIDnumber Resumes the numberPID process that we stopped before.
daemonskillall processnameKills processname.
daemonsps auxLists the aplications that are now running with his PID(Process IDentifier). ps aux | more Pauses between screens. Very useful to get information to kill a running process.
daemonstopShows the processes sorted by CPU use on real time, also free RAM and used SWAP.
daemonsxkillKills on X-windows the process that we select by clicking it with the mouse. It's the same as kill but on graphical mode. Hotkey: Ctrl+Alt+ESC
filesalias ls='ls --color=tty'When you type ls you'll see color output but only if the output goes to screen (not a file) you could insert this line in ~/.bash_profile to always do it.
filesdd if=/dev/fd0 of=diskimagenameMakes a disk image and saves it on diskimagename file.
filesdd if=diskimagename of=/dev/fd0Saves the diskimagename file to a floppy disk.
filesdfShows free disk space.
filesdu -c filesShows the total size used by the files.
filesdu -s directoryShows the directory size.
filesecho $PATHShows the current path.
filesemacs filenameEdits the filename Ctrl+X Ctrl+S (save), Ctrl+X Ctrl+C (quit).
filesfind /directory -name 'filename'Searches from directory the specified filename.
filesfor x in $(ls /directory) do echo $x done A little bash script to loop on the files in a directory.
filesgrepSearches for a string on a file. cat file.txt | grep stringtolookfor
filesjoe filenameText editor.
filesless file I'ts like a better more, allows to go up and down and doesn't load the all the entire file when you call it.
filesln -s /mnt/cdrom/Mame/roms /usr/games/lib/xmameMakes a soft link to the cdrom roms directory as if it was /usr/games/lib/xmame (xmame must not exist)
filesmke2fs /dev/hda2Formats the second partition from the first hard disk using the Linux format (ext2).
filesmore filenameShows filename on screen (it's lik: type | more on ms-dos) .
filesmount /dev/hda1 /mnt/c -t vfatMounts fat32 partition.
filespico filenameA basic text editor. Needs It's size in bytes is very low.
filesrm -rf directoryDeletes the directory and all the files within. No confirmation requiered.
filessedChanges a string for another one on a file (used with pipes).
filessed 's/stringA/StringB/' filename > newfilenameChanges the first occurrence of stringA on filename for stringB and saves it in newfilename.
filessed 's/stringA/stringB/g' filename > newfilenameChanges all the occurrence of stringA on filename for stringB and saves it in newfilename.
filestail -f filenameShows only the last lines of filename (good to follow on real-time log files).
filestar -zcvf filename.tar.gz directoryCompresses in tarball the directory and all subdirectories into filename.tar.gz
filestar -zxvf filename.tar.gzDecompress filename.tar.gz
fileswc filenameLine count, word cound and byte count for the file.
fileswhereis filenameFinds filename and says where it is using the internal data base, that must be updated. updatedb updates it.
fileszip -r targetfilename directoryCompress directory and all its folders on ficherodestino.zip
fileszip -r zipfilenameyouwant.zip desiredirectorynameCompresses using zip the desiredirectoryname and all the subdirectories.
imageconvert -resize 640x480 original.jpg modified.jpgConverts image to 640x480
imagemplayer videoyouwant.avi -vo aaPlays the video on ascii art.
network/etc/network/interfacesEdit this file to change IP on Debian
networkifconfigShows your IP also is used to configure your network card.
networkncftpAn improved ftp client for console
networknetstat -lnp --ipIf you type it being root, will display current running daemons.
networkscp root@192.168.0.201:/boot/vmlinux .Copies the file vmlinux remote from the host 192.168.201 via ssh to current directory.
networkwget -c --passive-ftp ftp://filenameDownloads the file or continues the download using FTP passive mode.
networkwget -c http://filenameDownloads the requested filename or continues the download if the connection was lost.
networkwget -rl 4 http://domainnameDownloads the website and all files on it until level 4
soundmpg123 -q /directory/*.mp3 &Plays in background from the shell the .mp3 music files allocated on the directory.
system/sbin/hdparm -d 1 /dev/hdaSets using_dma bit to 1 to enable Ultra-DMA access to disk.
system/sbin/hdparm -tT /dev/hdaPerforms a timing benchmark on device reads.
system/sbin/hdparm /dev/hdaShows hard disk configuration parameters.
systembashsh Extension.
systembcIs a text mode calculator.
systemchsC shell.
systemdpkg -i package.debInstalls package.deb (Debian).
systemif [ -x /path/to/dnetc ]; then echo "Starting Distributed.net Client..." /path/to/dnetc -quiet fiThe file /etc/rc.d/rc.local is like autoexec.bat from ms-dos and we cand add this lines on it. If it's not running, will start dnetc application.
systemkshKorn shell, combines sh and csh.
systemlastShow list of last logged in users (reads /var/log/wtmp).
systemltrace elfexecutableTraces an elf executable program (nice hacking tool)
systemnohup scriptname &Runs scriptname in background and keeps running even if you close the window shell.
systempdkshksh Extension.
systemrpm -e rpmnameUninstalls rpm previous isntalled package (the rpmname must be obtained from rpm -qa and without .rpm).
systemrpm -qa |grep ftpList current installed ftp servers.
systemrpm -qpl package.rpmShows what files are on the package.
systemrpm -Uvh package.rpmUpgrades an installed package with the new one or installs it.
systemsetterm -blank 0Turns off console blank screensaver (that is On by default), you can put it on /etc/rc.local
systemshChanges to bash shell (Unix standard).
systemshutdown -h nowShutdowns the computer. The same as halt
systemshutdown -r nowReboots the computer. The same as reboot.
systemstrace -s 200 executableIntercepts system calls which are received by a process -s 200 is for string size 200 (nice hacking tools)
sytemrpm -qi rpmnameQuerys about version, complete description and more info for the package.
timeat 7:00 cdplaydSets the computer to play the cd at 7:00.
timeatqLists the automatic programmed jobs.
timeatrm 8Deletes automatic job number 8.
timedateShows system date and time.
timedate -s "04/25/05" +"%D"Changes sytem date to April, 25th 2005 .
timedate -s "15:00:00" +"%T"Changes system time to 15:00.
timeEdit this file to memorize a job: etc/crontabEx: 00 00 20 10 * echo 'The winter is here' >/dev/null (this last command is to not send a mail to root). On the next directories you could copy applications or scripts that will run every time period. /etc/cron.hourly/ /etc/cron.daily/ /etc/cron.wee
timerdate -p ntp.nasa.govShows the server date and time.
timerdate -s ntp.nasa.govSynchronizes your time and date with the server.
timetime applicationRuns the application and when it's finished shows the running time.
timeuptimeShows the total time since the computer was turned on.
users/usr/bin/gpasswd -a user groupAsign that user to that group.
userschmod mode fileChanges the file permissions
userschown user:group fileChanges the file user and group owner.
usersgpasswd -d user groupTo remove users from a group. The same is to edit: /etc/group
usersgroups usernameShows groups that username is on
usersid usernameShows user identification and groups where he is on.
userssuYou become root until type: exit.
userssu -Becomes root and reads root user's environment.
usersusermod -G group1,group2 userAsign groups to a user.
XsetxkbmapTry if your AltGr keys doesn't work on X mode.
Xswitchdesk desktoptypeChanges the default desktop to anther (gnome, kde, wmaker, etc...).