You are on page 1of 3

DEBIAN/UBUNTU LINUX COMMAND REFERENCE

Version 1.0 May 2010 t94xrnz@gmail.com


Important Note:
Linux does not recognise a capitalized H the same as a small h, so in Linux, h is not H and H is not h – they are completely seperate characters.

SYSTEM
shutdown -h now Shutdown the system now and do not reboot
halt Stop all processes immediately – same as above.
shutdown -r 5 Shutdown the system in 5 minutes and reboots the system
shutdown -r now Shutdown the system now and reboot.
reboot Stop all processes and then reboot – same as above.
sudo <command> Runs any command as 'SuperUser' aka Root/Administrator. VERY IMPORTANT!! Otherwise some stuff wont work...
gksudo <gnomeapp> Run GNOME application or file as SuperUser.
sudo !! Forgotten that your previous command requires sudo privilages, this will run that command again except with sudo.

FILE MANAGEMENT
ls -l List files in current directory using long format
ls -lh List files in current directory using long format, produce file & directory dizes in K/M/G file sizes.
ls -lha List files just same as 'ls -lh' but shows hidden files. (like .bashrc and .htaccess or .conkyrc)
ls -F List files in current directory and indicate the file type
ls -laC List all files in current directory in long format and display in columns
rm name Remove a file or directory
rm -rf name Kill off an entire directory and all it’s includes files and subdirectories – never run: ' rm -rf / ' for any reason!
cp filename /dirname Copy the file called filename to the /dirname directory
cp filename filename2 “Save As” - duplicate the file, save it under a different name.
mv filename /dirname Move the file called filename to the /dirname directory
mv filename1 file01 Rename a file entirely.
cat Display the file specified
nano file.t Nano file edtor – CTRL-X to quit, CTRL-O to save – requires sudo to edit system files.
man -k keyword Display man pages containing keyword
more filetoview Display the file called filetoview one page at a time, proceed to next page using the spacebar
head filetoview Display the first 10 lines of the file called filetoview
head -20 filetoview Display the first 20 lines of the file called filetoview
tail filetoview Display the last 10 lines of the file called filetoview
tail -20 filetoview Display the last 20 lines of the file called filetoview
less file.txt Scroll through the contents of a text file. Press q when done.
command > file.txt Any command that renders an output can be “piped” into a file specified.
Hidden Files
Hidden configuration files, eg. .conkyrc – are hidden because unless specified the ls command doesn't present them to view because of the full stop at the start
of the line. A file named hidden.t is viewable to hide it rename it to .hidden.t and it wont appear in GNOME or Terminal unless hidden files are wanted to view.
Directories can also be hidden with this method.

INSTALLING SOFTWARE PACKAGES (DEBIAN/UBUNTU)


Syntax Description Example
sudo dpkg -i {.deb package} Install the package dpkg -i zip_2.31-3_i386.deb
sudo dpkg -i {.deb package} Upgrade package if it is installed else install a fresh copy of package dpkg -i zip_2.31-3_i386.deb
sudo dpkg -R {Directory-name} Install all packages recursively from directory dpkg -R /tmp/downloads
sudo dpkg -r {package} Remove/Delete an installed package except configuration files dpkg -r zip
sudo dpkg -P {package} Remove/Delete everything including configuration files dpkg -P apache-perl
dpkg -l
List all installed packages, along with package version and short dokg -l | less
sudo dpkg -l
description dpkg -l '*apache*'
dpkg -l | grep -i 'sudo'
List individual installed packages, along with package version and short
sudo dpkg -l {package} dpkg -l apache-perl
description
Find out files are provided by the installed package i.e. list where files were dpkg -L apache-perl
sudo dpkg -L {package}
installed dpkg -L perl
List files provided (or owned) by the package i.e. List all files inside
sudo dpkg -c {.Deb package} dpkg -c dc_1.06-19_i386.deb
debian .deb package file, very useful to find where files would be installed
Find what package owns the file i.e. find out what package does file dpkg -S /bin/netstat
sudo dpkg -S {/path/to/file}
belong dpkg -S /sbin/ippool
sudo dpkg -p {package} Display details about package package group, version, maintainer, dpkg -p lsof
Architecture, display depends packages, description etc.
sudo dpkg -s {package} | grep status Find out if Debian package is installed or not (status) dpkg -s lsof | grep Status

DOWNLOADING & INSTALLING PACKAGES (DEBIAN/UBUNTU)


sudo apt-get install <package_name> Installs a package and its dependencies, if any.

sudo apt-get remove <package_name> Removes the specified package.

sudo apt-get update Updates the APT package index (A list of all packages available from its repositories)

sudo apt-get upgrade Upgrades all the installed packages on the current system.

sudo apt-get check verifies system's integrity using apt


sudo apt-get clean removes the downloaded packages from the cache directory freeing some disk space at your system.
sudo apt-get autoremove autoremove is used to remove packages that were automatically installed to satisfy dependencies for some
package and that are no more needed.
sudo apt-get autoremove <package> Same as above, but does it at the same when you remove the unwanted application.
sudo apt-get install -f Fixes broken packages – installation failures, incomplete packages and such.
sudo apt-get <package> -y The '-y' tack installs the package(s) you want, without prompting.
sudo apt-get dist-upgrade Same as apt-get but installs base packages and tries to upgrade everything installing new packages if needed.
sudo apt-cache search music Will search the apt database for any packages related to 'music'.

NETWORK
ping host/ip ping host and output results
whois domain.com get whois information for domain
dig domain.com get DNS information for domain
dig -x host reverse lookup host
wget http://domain/file.t download file
wget -c http://domain/file.t Resume/Continue a stopped download or partially downloaded file.
lynx If installed, this provides a text only based browser.
ifconfig Displays information about network adapters. Apply adapter name for details about that specific adapter.
iwconfig Displays wireless network information

MISC SHORTCUTS / COMMANDS


Ctrl+C halts/cancels the current command
Ctrl+Z stops the current command, resume with fg in the foreground or bg in the background
Ctrl+D log out of current session, similar to exit
Ctrl+W erases one word in the current line
Ctrl+U erases the whole line
Ctrl+R type to bring up a recent command
!! repeats the last command – Up arrow key also does the same job.
exit log out of current session
CTRL+ALT+F1 - 6 Access Console terminals tty1-6
CTRL+ALT+F7 - 12 X Screens, Assigned for GUI software, like GNOME, KDE and such

SYSTEM INFO
date show the current date and time
cal show this month's calendar
uptime show current uptime
w display who is online
whoami who you are logged in as
finger user display information about user
uname -a show kernel information
lsb_release -a Full release info of any LSB distribution
cat /proc/cpuinfo cpu information
cat /proc/meminfo memory information
man command show the manual for command
df show disk usage
df -h Show dis usage, but with sizes human readable.
du show directory space usage
free show memory and swap usage
last Displays your last logins.
sudo hdparm -i /dev/sda Show info about disk sda – Note: Other drives like sdb sdc sdd sde sdf and so on can be used.
sudo hdparm -tT /dev/sda Do a read speed test on disk sda
sudo badblocks -s /dev/sda Test for unreadable blocks on disk sda

SERVICES
sudo service (name) restart Restarts the service specified
sudo service (name) stop Stops the service.
sudo service (name) start Starts the service – provides a process number.
sudo service (name) status Provides a status of service either stop or start.
This command, provides a lot more versatility. Commands like stop start do not require brackets.
sudo /etc/init.d/(name) {start|stop|reload|force-reload|restart|try-restart|status}

SSH (Secure Shell)


ssh user@ipaddress Log into a remote address – standard (defualt port 22)
ssh -l user ipaddress Same as above, but different.
ssh -p 23 user@ipaddress Log into a remote address via external port 23
ssh-copy-id user@host Add your key to host for user to enable a keyed or passwordless login.

SCREEN
screen Opens a new screen with an new pid
screen -x Attaches to active screen or produces list of numerous screens with pids
screen -x 3042 Attach to a specific screen out of (for example) 5 screens, assigned with pid 3042
All screen commands start with CTRL-a.
Ctrl-a ? help and summary of functions
Ctrl-a c create an new window (terminal)
Ctrl-a Ctrl-n and Ctrl-a Ctrl-p to switch to the next or previous window in the list, by number.
Ctrl-a Ctrl-N where N is a number from 0 to 9, to switch to the corresponding window.
Ctrl-a " to get a navigable list of running windows
Ctrl-a a to clear a missed Ctrl-a
Ctrl-a Ctrl-d to disconnect and leave the session running in the background
Ctrl-a x lock the screen terminal with a password.

COMPRESSION
tar cf file.tar files create a tar named file.tar containing files
tar xf file.tar extract the files from file.tar
tar czf file.tar.gz files create a tar with Gzip compression
tar xzf file.tar.gz extract a tar using Gzip
tar cjf file.tar.bz2 create a tar with Bzip2 compression
tar xjf file.tar.bz2 extract a tar using Bzip2
tar -zxvf archive.tar.gz Decompress the files contained in the zipped and tarred archive called archive.
tar -zxvf archive.tgz

FILE INTEGRITY & SECURITY


md5deep file.tar.gz Generate an md5 checksum from file
sha1 file.tar.gz Generate an sha1 checksum from file
rmd160 file.tar.gz Generate a RIPEMD-160 checksum from file
stealth A stealthy File Integrity Checker
steghide A steganography hiding tool
wipe privateinfo.doc Securely wipe a file from your hard drive. May require installation.
srm privateinfo.doc This command is a replacement for rm command. It removes each specified file by overwriting,
renaming, and truncating it before unlinking. May require installation.

USEFUL WEBSITES
[shell-fu]$ Shell-fu is a place for all those little command line goodies that you come across and then can
http://www.shell-fu.org/ never find again when you need them. Hopefully we'll end up with a comprehensive and easily
usable resource for anyone working with the shell.

You might also like