Basic Linux Commands
Basic Linux Commands
1) pwd COMMAND:
pwd - Print Working Directory. pwd command prints the full filename of
the current working directory.
SYNTAX:
The Syntax is
pwd [options]
2) cd COMMAND:
cd command is used to change the directory.
SYNTAX:
The Syntax is
cd [directory | ~ | ./ | ../ | - ]
3) ls COMMAND:
ls command lists the files and directories under current working directory.
SYNTAX:
The Syntax is
ls [OPTIONS]... [FILE]
OPTIONS:
-l Lists all the files, directories and their mode, Number of links,
owner of the file, file size, Modified date and time and filename.
-t Lists in order of last modification time.
-a Lists all entries including hidden files.
-d Lists directory files instead of contents.
-p Puts slash at the end of each directories.
-u List in order of last access time.
-i Display inode information.
4) rm COMMAND:
rm linux command is used to remove/delete the file from the directory.
SYNTAX:
The Syntax is
rm [options..] [file | directory]
OPTIONS:
5) mv COMMAND:
mv command which is short for move. It is used to move/rename file
from one directory to another. mv command is different from cp command
as it completely removes the file from the source and moves to the directory
specified, where cp command just copies the content from one file to
another.
SYNTAX:
The Syntax is
mv [-f] [-i] oldname newname
OPTIONS:
-f This will not prompt before overwriting (equivalent to --
reply=yes). mv -f will move the file(s) without prompting even
if it is writing over an existing target.
-I Prompts before overwriting another file.
6) cat COMMAND:
cat linux command concatenates files and print it on the standard output.
SYNTAX:
The Syntax is
cat [OPTIONS] [FILE]...
OPTIONS:
-A Show all.
-b Omits line numbers for blank space in the output.
7) cmp COMMAND:
cmp linux command compares two files and tells you which line numbers are
different.
SYNTAX:
The Syntax is
cmp [options..] file1 file2
OPTIONS:
8) cp COMMAND:
cp command copy files from one location to another. If the
destination is an existing file, then the file is overwritten; if the destination is
an existing directory, the file is copied into the directory (the directory is not
overwritten).
SYNTAX:
The Syntax is
cp [OPTIONS]... SOURCE DEST
9) echo COMMAND:
echo command prints the given input string to standard output.
SYNTAX:
The Syntax is
echo [options..] [string]
10)mkdir COMMAND:
mkdir command is used to create one or more directories.
SYNTAX:
The Syntax is
mkdir [options] directories
OPTIONS:
11) paste COMMAND:
paste command is used to paste the content from one file to another file. It is
also used to set column format for each line.
SYNTAX:
The Syntax is
paste [options]
OPTIONS:
16)whoami command
18)help option
With almost every command, ‘--help’ option shows usage summary for that
command.
$ date --help
This command gives a one line description about the command. It can be
used as a quick reference for any command.
$ whatis date
date (1) - print or set the system date and time
20)Manual Pages
$ man date
21)Info pages
Info documents are sometimes more elaborate than the man pages. But for some
commands, info pages are just the same as man pages. These are like web
pages. Internal links are present within the info pages. These links are called
nodes. Info pages can be navigated from one page to another through these
nodes.
$ info date
22) The touch command is a standard command used in UNIX/Linux operating
system which is used to create, change and modify timestamps of a file.
Basically, there are two different commands to create a file in the Linux system
which is as follows:
cat command: It is used to create the file with content.
touch command: It is used to create a file without any content. The file
created using touch command is empty. This command can be used when
the user doesn’t have data to store at the time of file creation.
touch file_name
touch File1_name File2_name File3_name
touch -a: This command is used to change access time only. To change or
update the last access or modification times of a file touch -a command is used.
Syntax:
touch -a fileName
touch -c : This command is used to check whether a file is created or not. If not
created then don’t create it. This command avoids creating files.
Syntax:
touch -c fileName
23. whoami
The whoami command tells you your username.
[root@RHEL5 ~]# whoami
Root
24. who
The who command will give you information about who is logged on the
system.
[paul@RHEL5 ~]$ who
root tty1 2008-06-24 13:24
sandra pts/0 2008-06-24 14:05 (192.168.1.34)
paul pts/1 2008-06-24 16:23 (192.168.1.37)
25.who am i
With who am i the who command will display only the line pointing to your
current
session.
[paul@RHEL5 ~]$ who am i
paul pts/1 2008-06-24 16:23 (192.168.1.34)