Linux Commands
Linux Commands
Linux Commands
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.
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.
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
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}
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
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.