Unix Shell Commands
Index
Sno Command Page
1 mkdir
2 rmdir
3 cat
4 cd
5 cp
6 mv
7 rm
8 ls
9 lsattr
10 lsof
11 chmod
12 chown
13 chgrp
14 cksum
15 cmp
16 dd
17 du
18 df
19 fsck
20 fuser
21 ln
22 mount
23 pwd
24 split
25 touch
26 umask
To view help for any command, we have three approaches.
1. <command> --help
2. Man <command>
3. Info <command>
1). <command> --help
Eg:
pubuntu@pubuntu:~$ mkdir --help
Usage: mkdir [OPTION] DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, --mode=MODE set file mode (as in chmod), not a=rwx - umask
-p, --parents no error if existing, make parent directories as needed
-v, --verbose print a message for each created directory
-Z, --context=CTX set the SELinux security context of each created
directory to CTX
--help display this help and exit
--version output version information and exit
Notes: It displays the details within the same shell prompt.
2). Man <command>
Eg: pubuntu@pubuntu:~$ man mkdir
NAME
mkdir - make directories
SYNOPSIS
mkdir [OPTION] DIRECTORY...
DESCRIPTION
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, --mode=MODE
set file mode (as in chmod), not a=rwx - umask
-p, --parents
no error if existing, make parent directories as needed
-v, --verbose
print a message for each created directory
-Z, --context=CTX
set the SELinux security context of each created directory to CTX
--help display this help and exit
--version
output version information and exit
Notes: It displays the details of the command in another shell prompt.
Here…to scroll the page use and arrow keys.
To view next page press ‘space’ key.
To exit press ‘q’ key.
3). Info <command>
Eg: pubuntu@pubuntu:~$ info mkdir
NAME
mkdir - make directories
SYNOPSIS
mkdir [OPTION] DIRECTORY...
DESCRIPTION
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options
too.
-m, --mode=MODE
set file mode (as in chmod), not a=rwx - umask
-p, --parents
no error if existing, make parent directories as needed
-v, --verbose
print a message for each created directory
-Z, --context=CTX
set the SELinux security context of each created directory to
CTX
--help display this help and exit
--version
output version information and exit
Notes: It gives the same details like man command, except it displays the details in help document.
From here….to exit----press ‘q’ key
……..To scroll----Use up and down arrow keys.
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
File System Commands
1.mkdir:
NAME
mkdir - make directories
SYNOPSIS
mkdir [OPTION] DIRECTORY...
DESCRIPTION
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, --mode=MODE
set file mode (as in chmod), not a=rwx - umask
-p, --parents
no error if existing, make parent directories as needed
-v, --verbose
print a message for each created directory
-Z, --context=CTX
set the SELinux security context of each created directory to
CTX
--help display this help and exit
--version
output version information and exit
2. rmdir:
NAME
rmdir - remove empty directories
SYNOPSIS
rmdir [OPTION]... DIRECTORY...
DESCRIPTION
Remove the DIRECTORY(ies), if they are empty.
--ignore-fail-on-non-empty
ignore each failure that is solely because a directory is non-empty
-p, --parents
Remove DIRECTORY and its ancestors. E.g., rmdir -p a/b/c is similar to rmdir a/b/c a/b a.
-v, --verbose
output a diagnostic for every directory processed
--help display this help and exit
--version
output version information and exit
3.cat
NAME
cat - concatenate files and print on the standard output
SYNOPSIS
cat [OPTION] [FILE]...
DESCRIPTION
Concatenate FILE(s), or standard input, to standard output.
-A, --show-all
equivalent to -vET
-b, --number-nonblank
number nonempty output lines
-e equivalent to -vE
-E, --show-ends
display $ at end of each line
-n, --number
number all output lines
-s, --squeeze-blank
suppress repeated empty output lines
-t equivalent to -vT
-T, --show-tabs
display TAB characters as ^I
-u (ignored)
-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB
--help display this help and exit
--version
output version information and exit
With no FILE, or when FILE is -, read standard input.
EXAMPLES
cat f - g
Output f’s contents, then standard input, then g’s contents.
cat Copy standard input to standard output.
4.cd
"cd" stands for change directory. It is the primary command for moving around the file system.
cd /usr
This command moves you to the "/usr" directory. "/usr" becomes your current working directory.
cd /usr/fred
Moves you to the "/usr/fred" directory.
cd /u*/f*
Moves you to the "/usr/fred" directory - if this is the only directory matching this wildcard pattern.
cd
Issuing the "cd" command without any arguments moves you to your home directory.
cd -
Using the Korn shell, this command moves you back to your previous working directory. This is very
useful when you're in the middle of a project, and keep moving back-and-forth between two directories.
5.cp
NAME
cp - copy files and directories
SYNOPSIS
cp [OPTION]... [-T] SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... -t DIRECTORY SOURCE...
DESCRIPTION
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
-a, --archive
same as -dpR
--backup[=CONTROL]
make a backup of each existing destination file
-b like --backup but does not accept an argument
--copy-contents
copy contents of special files when recursive
-d same as --no-dereference --preserve=links
-f, --force
if an existing destination file cannot be opened, remove it and try again
-i, --interactive
prompt before overwrite
-H follow command-line symbolic links in SOURCE
-l, --link
link files instead of copying
-L, --dereference
always follow symbolic links in SOURCE
-P, --no-dereference
never follow symbolic links in SOURCE
-p same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST]
preserve the specified attributes (default: mode,ownership,timestamps), if possible additional
attributes: context, links, all
--no-preserve=ATTR_LIST
dont preserve the specified attributes
--parents
use full source file name under DIRECTORY
-R, -r, --recursive
copy directories recursively
--remove-destination
remove each existing destination file before attempting to open it (contrast with --force)
--sparse=WHEN
control creation of sparse files
--strip-trailing-slashes
remove any trailing slashes from each SOURCE argument
-s, --symbolic-link
make symbolic links instead of copying
-S, --suffix=SUFFIX
override the usual backup suffix
-t, --target-directory=DIRECTORY
copy all SOURCE arguments into DIRECTORY
-T, --no-target-directory
treat DEST as a normal file
-u, --update
copy only when the SOURCE file is newer than the destination file or when the destination file is
missing
-v, --verbose
explain what is being done
-x, --one-file-system
stay on this file system
--help display this help and exit
--version
output version information and exit
By default, sparse SOURCE files are detected by a crude heuristic and the corresponding DEST file
is made sparse as well. That is the behavior
selected by --sparse=auto. Specify --sparse=always to create a sparse DEST file whenever the
SOURCE file contains a long enough sequence of zero
bytes. Use --sparse=never to inhibit creation of sparse files.
The backup suffix is ~, unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control
method may be selected via the --backup option or
through the VERSION_CONTROL environment variable. Here are the values:
none, off
never make backups (even if --backup is given)
numbered, t
make numbered backups
existing, nil
numbered if numbered backups exist, simple otherwise
simple, never
always make simple backups
As a special case, cp makes a backup of SOURCE when the force and backup options are given and
SOURCE and DEST are the same name for an existing,
regular file.
6. mv
NAME
mv - move (rename) files
SYNOPSIS
mv [OPTION]... [-T] SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...
DESCRIPTION
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
--backup[=CONTROL]
make a backup of each existing destination file
-b like --backup but does not accept an argument
-f, --force
do not prompt before overwriting
-i, --interactive
prompt before overwrite
--strip-trailing-slashes
remove any trailing slashes from each SOURCE argument
-S, --suffix=SUFFIX
override the usual backup suffix
-t, --target-directory=DIRECTORY
move all SOURCE arguments into DIRECTORY
-T, --no-target-directory
treat DEST as a normal file
-u, --update
move only when the SOURCE file is newer than the destination file or when the destination file is
missing
-v, --verbose
explain what is being done
--help display this help and exit
--version
output version information and exit
The backup suffix is ~, unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control
method may be selected via the --backup option or
through the VERSION_CONTROL environment variable. Here are the values:
none, off
never make backups (even if --backup is given)
numbered, t
make numbered backups
existing, nil
numbered if numbered backups exist, simple otherwise
simple, never
always make simple backups
7. rm
NAME
rm - remove files or directories
SYNOPSIS
rm [OPTION]... FILE...
DESCRIPTION
This manual page documents the GNU version of rm. rm removes each specified file. By default, it
does not remove directories.
If the -I or --interactive=once option is given, and there are more than three files or the -r, -R, or --
recursive are given, then rm prompts the
user for whether to proceed with the entire operation. If the response is not affirmative, the entire
command is aborted.
Otherwise, if a file is unwritable, standard input is a terminal, and the -f or --force option is not
given, or the -i or --interactive=always
option is given, rm prompts the user for whether to remove the file. If the response is not
affirmative, the file is skipped.
OPTIONS
Remove (unlink) the FILE(s).
-f, --force
ignore nonexistent files, never prompt
-i prompt before every removal
-I prompt once before removing more than three files, or when removing recursively. Less
intrusive than -i, while still giving protection
against most mistakes
--interactive[=WHEN]
prompt according to WHEN: never, once (-I), or always (-i). Without WHEN, prompt always
--one-file-system
when removing a hierarchy recursively, skip any directory that is on a file system different from
that of the corresponding command line
argument
--no-preserve-root
do not treat / specially
--preserve-root
do not remove / (default)
-r, -R, --recursive
remove directories and their contents recursively
-v, --verbose
explain what is being done
--help display this help and exit
--version
output version information and exit
By default, rm does not remove directories. Use the --recursive (-r or -R) option to remove each
listed directory, too, along with all of its
contents.
To remove a file whose name starts with a -, for example -foo, use one of these commands:
rm -- -foo
rm ./-foo
Note that if you use rm to remove a file, it is usually possible to recover the contents of that file. If
you want more assurance that the con
tents are truly unrecoverable, consider using shred.
8. ls