Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
102 views

Basic Commands

The document discusses basic Linux commands for file and directory management. It covers the pwd, ls, cat, touch, mkdir, and cd commands for printing the working directory, listing files and directories, creating and viewing files, creating directories, and navigating directories. The ls command has multiple options to view files and directories in different formats. The cat command can be used to create, view, and concatenate files. The touch command creates files or changes file timestamps. The mkdir command creates directories and can make nested directories. The cd command navigates and changes the current working directory.

Uploaded by

ramana6n
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views

Basic Commands

The document discusses basic Linux commands for file and directory management. It covers the pwd, ls, cat, touch, mkdir, and cd commands for printing the working directory, listing files and directories, creating and viewing files, creating directories, and navigating directories. The ls command has multiple options to view files and directories in different formats. The cat command can be used to create, view, and concatenate files. The touch command creates files or changes file timestamps. The mkdir command creates directories and can make nested directories. The cd command navigates and changes the current working directory.

Uploaded by

ramana6n
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

1

1
Basic Commands

Print
PrintWorking
WorkingDirectory
Directory
[root@comp1 ~]# pwd
[root@comp1 ~]# pwd

Shows
Showslist
listof
offiles
files&
&directories
directories
[root@comp1 ~]# ls <options> <arguments>
[root@comp1 ~]# ls <options> <arguments>

2
ls Command

Listing
Listingof
of files
filesand
anddirectories
directories along
alongwith
with the
theattributes
attributes
[root@comp1 ~]#
[root@comp1 ~]# ls l ls l or
or
[root@comp1
[root@comp1~]# ~]#llll

Listing
Listingof
ofall
allfiles
filesand
anddirectories
directories including
includingthe
thehidden
hidden
root@comp1 ~]# ls
root@comp1 ~]# ls -a -a

Listing
Listingof
ofall
allfiles
filesand
anddirectories
directoriesin
inreverse
reverseorder
order
[root@comp1
[root@comp1~]#~]#ls
ls -r
-r
3

3
ls Command

Listing
Listingof
offiles
filesand
anddirectories
directoriesalong
alongwith
with the
the inode
inode numbers
numbers
[root@comp1 ~]# ls
[root@comp1 ~]# ls il il

Listing
Listingof
ofthe
theattributes
attributesof
ofaaparticular
particularfile
fileor
or directory
directory
[root@comp1 ~]# ls -ld <directory>
[root@comp1 ~]# ls -ld <directory>

Shows
Showsthethelist
listof
offiles
filesin
inTree
Treestructure
structure
[root@comp1
[root@comp1~]#
~]#ls
ls -R
-R <directory>
<directory>
4

4
Creation of Files

By using three methods we can create files

cat command

touch command

vi editor

Displaying
Displaying&&Creating
CreatingText
TextFiles
Files
[root@comp1 ~]# cat <options> <arguments>
[root@comp1 ~]# cat <options> <arguments>

5
cat command

To
Tocreate
createaafile
file
[root@comp1 ~]# cat > <filename>
[root@comp1 ~]# cat > <filename>

To
Toview
viewthe
thecontent
contentof
ofaafile
file
[root@comp1
[root@comp1~]#
~]#cat
cat <filename>
<filename>

To
Toappend
appendaafile
file
[root@comp1 ~]# cat >> <filename>
[root@comp1 ~]# cat >> <filename>

To
Totransfer
transferthe
thecontents
contentsofoffile1
file1&
&file2
file2to
tofile3
file3
[root@comp1 ~]# cat <file1> <file2> >> <file3>
[root@comp1 ~]# cat <file1> <file2> >> <file3>
6

6
touch command

To
Tocreate
createaafile
filewith
withzero
zerobytes
bytesasaswell
wellas
asto
tochange
changethe
thetime
time
stamp of file or directory.
stamp of file or directory.
[root@comp1
[root@comp1~]#~]#touch
touch <filename>
<filename>

To
Tocreate
createmultiple
multiplefiles
files
[root@comp1
[root@comp1~]#
~]#touch
touch <file1>
<file1> <file2>
<file2> <file3>
<file3>

7
Creating Directories

To
Tocreate
createaadirectory
directory
[root@comp1
[root@comp1 ~]# mkdir <directory name>
~]# mkdir <directory name>

To
Tocreate
createmultiple
multipledirectories
directories
[root@comp1
[root@comp1 ~]# mkdir <dir1> <dir2>
~]# mkdir <dir1> <dir2> <dir3>
<dir3>

To
Tocreate
createnested
nesteddirectories
directories
[root@comp1
[root@comp1~]#
~]#mkdir
mkdir -p
-p <dir1>/<dir2>/<dir3>
<dir1>/<dir2>/<dir3>

8
Navigation of Directories

To
Tochange
changethe
thedirectory
directory
[root@comp1 ~]# cd <path of the directory>
[root@comp1 ~]# cd <path of the directory>

To
Tochange
changedirectory
directoryone
one level
levelback
back
[root@comp1 ~]# cd ..
[root@comp1 ~]# cd ..

To
Tochange
changedirectory
directory two
twolevels
levelsback
back
[root@comp1
[root@comp1~]#
~]#cdcd../..
../..

9
Navigation of Directories

To
Tochange
changedirectory
directory to
tolast
lastworking
workingdirectory
directory
[root@comp1 ~]# cd
[root@comp1 ~]# cd

To
Tochange
changedirectory
directory to
tohome
home directory
directory
[root@comp1
[root@comp1~]#
~]#cd
cd or
or
[root@comp1
[root@comp1~]#
~]#cd
cd ~~

10

10
Removing a File or Directory

To
Toremove
removeaa file
file
[root@comp1 ~]# rm <filename>
[root@comp1 ~]# rm <filename>

To
Toremove
removeempty
empty directory
directory
[root@comp1
[root@comp1 ~]# rmdir <directoryname>
~]# rmdir <directory name>

To
Toremove
remove directory
directoryrecursively
recursively and
andforcefully
forcefully
[root@comp1
[root@comp1~]#
~]#rm
rm rf rf <directory
<directoryname>
name>

11

11
Copying a File or Directory

To
Tocopy
copyaafile
file
[root@comp1
[root@comp1~]#
~]#cp
cp <source
<sourcefile
filepath>
path><destination
<destinationfile
filepath>
path>

To
Tocopy
copyaadirectory
directory
[root@comp1
[root@comp1~]#
~]#cp
cp rr <source
<sourcedir
dirpath>
path> <destination
<destinationdir
dirpath>
path>

12

12
Moving / Renaming a File or Directory

To
Tomove
moveaa file/dir
file/dirto
toaadifferent
different location
location
[root@comp1
[root@comp1 ~]# mv <source path> <destination
~]# mv <source path> <destinationpath>
path>

To
To rename
rename file/dir
file/dirmove
moveat
atsame
samelocation
location
[root@comp1
[root@comp1~]#
~]#mvmv <old
<oldname>
name> <new
<newname>
name>

13

13

You might also like