Basic UNIX Commands
Biru Rajak
Coordinator, Computer Sc. Dept.
Asansol Girls’ College
BCA Coordinator, KNU (Add. Charge)
[email protected]
man
• Manual Pages
• Contains information about almost everything
- Other Commands
- System Calls
- C Library Functions
Syntax:
man <command name>
Example:
% man ls
which
• Displays a path name of a command
• Searches a path environmental variable for the
command and displays the absolute path
Syntax:
which <command name/app>
Example:
% which sh (shows which sh is actually in use)
whereis
• Display all locations of a command (or some
other binary, man page, or a source file).
• Searches all directories to find commands that
match the argument
Syntax:
whereis <command name>
Example:
% whereis sh
passwd
• Change your login password.
Syntax:
passwd
passwd <username>
Example:
% passwd is-05
date
• Displays dates in various formats
Example :
% date (in IST)
% date -u ( in GMT )
clear
• To clear the screen
Syntax:
% clear OR,
ctrl + L
alias
• Defines a new name for a command
Syntax:
alias <newcommand>='<oldcommand>'
Example:
% alias dt='date'
% dt
history
• Display a history of recently used commands
Syntax:
history <option>
Example:
%history 10
exit/logout
• Exit from your login session.
Example :
% exit
% logout
shutdown
• Causes system to shutdown or reboot
• May require super-user privileges
Example:
% shutdown -h now ( stop )
% shutdown -r now ( reboot )
File Management Commands
ls
• Lists directory contents
Syntax:
ls <option>
Examples:
% ls (lists all files except those starting with a “.”)
% ls –a
% ls –l
% ls -al
cat
• Takes a copy of a file and sends it to the
standard output
Syntax:
cat <filename>
Example:
% cat link.txt
more
• Display contents of large files page by
page or scroll line by line up and down.
Syntax:
more <option> <filename>
Examples:
% more –a.txt (press enter to see next page content)
% more -s a.txt (squeeze multiple space line into single)
less
• It is used for search navigation.
Syntax:
open the file with
% less <filename> then at end of file
Example:
/<pattern> (want to search)-Forward
?<pattern> (want to search)-Forward
cp
• Copies files/directories
Syntax:
% cp [options] <source> <destination>
Example:
% cp a.txt b.txt
(Useful option: -i to prevent overwriting existing files and
prompt the user to confirm)
mv
• Moves or renames files/directories
Syntax:
% mv <source> <destination>
(The <source> file gets removed)
Example:
% mv b.txt d.txt
rm
• Removes file(s) and/or directories.
Syntax:
% rm <options> <filename>
Example:
% rm d.txt
diff
• Compares file and, shows where they differ.
Syntax:
% diff <filename1> <filename2>
Example:
% diff a.txt b.txt
find
•Searching a file in a directory tree
Syntax:
%find <option> <filename>
Example:
% find -name "a.txt"
cd
• Changes your current directory to a new one.
Syntax:
cd <dirname>
Example:
% cd /usr/home/example
mkdir
• Creates a directory
Syntax:
% mkdir <dirname>
Example:
% mkdir etcs lab
rmdir
• Removes a directory
Syntax:
% rmdir <dirname> (empty)
% rm -r <dirname>
Example:
% rm -r etcs
wc
• Tells you how many lines, words, and
characters there are in a file
Syntax:
% wc filename
Example:
% wc a.txt (line words char)
pwd
• Displays the present working directory, i.e.
your current directory.
Example:
% pwd
chown
• To change the owner and owning group of files
Syntax:
• chown <owner/user> <filename>
• chown <owner-user:owner-group >
<filename>
Example:
% chown is-05 file.txt
chmod
• To change permissions of files or directories
Syntax:
% chmod options permissions filename
Example:
% chmod 644 file.htm
grep
• To print lines of input matching a specified
pattern
Syntax:
% grep <option> <pattern> <file>
Example:
% grep chope a.txt
User/Group Management
Commands
useradd
• To add a new user
Syntax:
useradd <username>
Example:
# useradd xyz
userdel
• To delete a user
Syntax:
% userdel <username>
Some Other Commands
zip
• Compresses files, so that they take up much
less space
Syntax:
% zip -r <filenames.zip> <file1> <file2>
Example:
% zip –r foo.zip a.txt b.txt etcs
unzip
• Uncompress the files compressed by gzip
Syntax:
% unzip <-options> filename
(zipfile name without extension)
Example:
% unzip -r foo
who
• Tells you who's logged on, and where they're
coming from.
Example:
% who
whoami
• Displays the same information as who, but
only for the terminal session from where the
command was issued.
Example:
% whoami
last
• Tells you when the user last logged on and off
and from where.
Syntax:
% last -1 username
(Without any options, last will give you a list of
everyone's logins)
echo
• Displays a line of text
Syntax:
echo <option> <string>
Example:
% echo Hello, World!
% x=10
% echo The value of x is $x.
ps
• Displays information about a selection of the
active processes.
• Contains lots of information about them
including the process ID
Syntax:
% ps [-options]
kill
• Kills (ends) the processes with the ID given
Syntax:
% kill <PID>
ifconfig
• To see the IP Address
Syntax:
% ifconfig <option>
Example:
% ifconfig -a
telnet
• To connect to a remote host
Syntax:
% telnet [-options] <hostname/ipaddress>
Example:
% telnet myhost.com
ftp
• To download/upload files from/to a remote
host which is set up as an ftp-server
Syntax:
% ftp <hostname/ipaddress>
Example:
% ftp 172.31.128.116