RHEL 7 Tutorial Managing Files and Directories

In Linux Operating System Everything is considered as a File. If you know Managing Files and Directories Effectively  that way you get more commanding on Operating system. In this Article We are going to learn RHEL 7 Tutorial Managing Files and Directories.

RHEL 7 Tutorial Managing Files and Directories

Creating files and multiple files at a time using touch command, let’s see practical examples

[root@ArkIT touch]#touch samplefile
[root@ArkIT touch]#ls
samplefile
[root@ArkIT touch]#
[root@ArkIT touch]#touch file{1..10}.txt
[root@ArkIT touch]#ls
file10.txt file2.txt file4.txt file6.txt file8.txt samplefile
file1.txt file3.txt file5.txt file7.txt file9.txt

Listing the files and directories using ls command

25 practical examples with ls command

Types of Files in Linux

File TypeSymbolDescription
Regular fileNormal File
DirectorydDirectory can be stored with other files
LinklShortcut to the original file
Special FilecSuch as /dev file. Character device file
Socket FilesThe file system’s access control
PipepSpecial file that allows processes to communicate
Block FilebBlock Device File

Creating directories and parent directory structure using single command

[root@ArkIT ~]#mkdir dir1
[root@ArkIT ~]#ls
anaconda-ks.cfg dir1 initial-setup-ks.cfg Public touch
chmod Documents Music ravi Videos
Desktop Downloads Pictures Templates wel

[root@ArkIT ~]#mkdir -p /dir2/ravi/test
[root@ArkIT ~]#ls -R /dir2
/dir2:
ravi

/dir2/ravi:
test

/dir2/ravi/test:

Copy files from one location to another location

cp is the command to copy the files within the server, from one location to another location

[root@ArkIT ~]#cp anaconda-ks.cfg ravi wel /dir2/
cp: overwrite ‘/dir2/ravi’? y
cp: cannot overwrite directory ‘/dir2/ravi’ with non-directory
[root@ArkIT ~]#ls -l /dir2/
total 8
-rw-------. 1 root root 1374 Feb 12 22:15 anaconda-ks.cfg
drwxr-xr-x. 3 root root 17 Feb 12 21:54 ravi
-rw-r--r--. 1 root root 37 Feb 12 22:15 wel

Copy Directories

[root@ArkIT ~]#cp -Rv dir1/ /dir2/
‘dir1/’ -> ‘/dir2/dir1’
[root@ArkIT ~]#ls -l /dir2/
total 8
-rw-------. 1 root root 1374 Feb 12 22:15 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Feb 12 22:17 dir1
drwxr-xr-x. 3 root root 17 Feb 12 21:54 ravi
-rw-r--r--. 1 root root 37 Feb 12 22:15 wel

Move Files and Directories

Using mv command we can simple move files / directories from source to destination

[root@ArkIT ~]#mv dir1/ /dir2/
mv: overwrite ‘/dir2/dir1’? y

[root@ArkIT ~]#ls
anaconda-ks.cfg Desktop Downloads Music Public Templates Videos
chmod Documents initial-setup-ks.cfg Pictures ravi touch wel

[root@ArkIT ~]#ls /dir2/
anaconda-ks.cfg dir1 ravi wel

Deleting files and directories 

rm is the command to remove / delete files and directories

[root@ArkIT ~]#rm ravi
rm: remove regular file ‘ravi’? y
[root@ArkIT ~]#rm -f wel
[root@ArkIT ~]#rm -f touch/
rm: cannot remove ‘touch/’: Is a directory
[root@ArkIT ~]#rm -rf touch/

That’s about RHEL 7 Tutorial Managing Files and Directories.

Related Articles

25 commonly used commands in Linux

find command with 30 practical examples

chmod command to grant file / directory permissions

Complete RHCSA and RHCE Certification study Guide

Thanks for your wonderful Support and Encouragement

Stay Connected with us. Learn More and Earn More

ARK

My Name is ARK. Expert in grasping any new technology, Interested in Sharing the knowledge. Learn more & Earn More

You may also like...

Leave a Reply