ls
list contents in preset folder
ls -l : list with more details
cd
change to a different directory
cp <SOURCE> <DESTINTION>
copy contents to a different location
-r for directories
mv
rename a file/folder OR move it to a different location
rm
delete a file
-r in case of directories
NOTE : Always think twice before using 'rm' command
file <FILENAME>
displays the file type
grep <PATTERN> <FILENAME>
searches and prints if a particular PATTERN is present in a FILENAME
cat <FILENAME>
prints the textual contents in FILENAME
more & less
unlike cat for viewing contents in a FILENAME page-wise
tail
outputs last few lines of a FILENAME
-f used to get the real-time output of a file, say a logfile eg:- tail -f /var/log/httpd/error_log
head
opposite of tail , displays top few lines
ln
create links to an existing file
-s used to create symbolic links eg:- ln -s <TARGET> <LINKNAME>
touch <FILENAME>
change time-stamps of FILENAME to that of present, and if FILENAME doesn't exists an empty one
with present time-stamps is created.
mkdir
create a directory
df
outputs disk space usage
-f outputs a much friendly output
du
outputs the file/folder space usage
-sch results a grand total space usage in friendly format
chmod <BITS> <FILE/FOLDER>
alter permissions for a file/folder
BITS -> r w e r w e r w e
----- ----- -----
U G O
each 'r' 'w' and 'e' can be 1 to enable OR 0 to disable
chown USER:GROUP <FILE/FOLDER>
alter ownerships to that for a particular user and group.
find
search for a particular file/folder
which <COMMAND>
shows the exact location of a shell command
locate <FILE>
prints all files with name FILE in the system
updatedb
'locate' needs a database which stores all the files and its location, 'updatedb' updates this database, by
default it will be in system daily crons.
history
pulls out a list of all the commands that are entered in a shell
mount <DEVICE> <MOUNTPOINT>
mounts the DEVICE (a hard disk partition, CD-ROM, external drive etc.) to a folder MOUNTPOINT.
umount <DEVICE or MOUNTPOINT>
su <USER>
switches to a different USER
sudo
executes a command with another user privileges.
However a user needs permission to execute sudo which can be given by editing the /etc/sudoers file
or executing 'visudo' in redhat based systems.
ifconfig
configure a network interface, without any arguments it lists all the network interfaces in the system
eg:- ifconfig eth0 192.168.1.50
- this assigns the IP 192.168.1.50 to the primary network card
ssh HOST -l USER -p PORT
a remote login program to a SSH server
scp
remote copying of files through ssh protocol
eg:- scp user1@server1.com:/file1 filecopy
use -r for directories
rsync
a remote/local file copying and syncing program
eg:- rsync -avz user1@server1.com: /home/user1
rsync -avz /home/user1/ /backup/user1/
vim
a text based file editor in linux/unix
for vim insert mode : INSERT or I key
for vim escape mode : ESC key
:w - save changes
:q - quit
:wq - save & quit
:q! - quit without saving
ftp
a text based FTP client from shell
mail
mail program from shell
mail -s SUB TO_ADDRESS -b BCC -c CC -a ATTACHMENT < FILENAME (with contents)
telnet
connect to remote hosts using telnet protocol
telnet <HOST> <PORT>
tar -c <ARCHIVE.tar> <FILE1 FILE2>
archive files together to a single file
-c : create archive
tar -x <ARCHIVE.tar>
-x : extract archive
screen
opens a shell session and any program started here will run as long as the screen in running, even if the
user logs out.
w
gives a list of who all are logged in and what each of them are doing
uptime
shows how long the system has been up and running
ps
list current running processes
ps aux : lists all running processes in the system.
free
shows memory usage in the system
free -m : mostly used
uname
prints system information such as OS, architecture, kernel version, hostname etc.
eg:- uname -a
kill
terminates a particular PID in the system
eg:- kill -9 <PID>
killall -9 httpd
ping <HOST or IP>
send ICMP requests to HOSTS
dig <HOSTNAME>
DNS lookup utility
dig <HOSTNAME> <NAMESERVER> : DNS lookup for HOSTNAME in NAMESERVER
host <HOST or IP>
DNS lookup utility to convert hosts to IP and vice-versa
eg:- host google.com
top
displays running processes in real-time.
top -c : mostly used, shows top results with full commands
nice
assign priorities for a program, default value is 10.
with option -n the range can be from -20 (most favorable scheduling) to 19 (least favorable).
eg:- nice top -c
whois <DOMAIN or IP>
provides domain name registration details OR IP ownership details.
eg:- whois google.com
netstat
outputs all present network connections to server.
netstat -plan : commonly used.
iptables
default firewall in linux
-A
Append rule to end of a chain
-I
Insert rule
-F
Flush. Deletes all the rules in the selected table
-p <protocol-type> protocol types include icmp, tcp, udp, and all
--sport <port> source port
--dport <port> destination port
-s <ip-address>
source IP address
-d <ip-address>
destination IP address
-j <target>
target can be ACCEPT, REJECT or DROP. select depending on what you wish to
do with the new rule.
-nL Lists the present rules