You are on page 1of 6

Gaza Community College for Tourism and Applied Studies

Red Hat® RHCSA™/RHCE® 7


Cert Guide:
Red Hat Enterprise Linux 7

CHAPTER 2 :Managing Files From the


Command Line

Prepared by: shadi alaydi


Absolute paths and Relative paths:
-For standard Linux file systems, the path name of a file, including all / characters, may be no
more than 4095 bytes long.
-Each component of the path name separated by / characters may be no more than 255 bytes
long.
root@shadi-virtual-machine:~# cd
root@shadi-virtual-machine:~# cd /root/Videos
root@shadi-virtual-machine:~# cd Videos
root@shadi-virtual-machine:~# pwd
root@shadi-virtual-machine:~# cd /root/Documents
root@shadi-virtual-machine:~# cd ~shadi (go to the home directory of the user)
root@shadi-virtual-machine:~# cd - (go to the previous directory)
root@shadi-virtual-machine:~# cd .. (up one level)
root@shadi-virtual-machine:~# cd ../.. (up two levels)
========================================

list files:
root@shadi-virtual-machine:~# ls
root@shadi-virtual-machine:~# ls -l ~ (long list)
root@shadi-virtual-machine:~# ls -a (all files and directories including hidden ones)
root@shadi-virtual-machine:~# ls -la
root@shadi-virtual-machine:~# ls -lh (human readable)
root@shadi-virtual-machine:~# ls -R (Recursive)
root@shadi-virtual-machine:~# ls -t (access time)
root@shadi-virtual-machine:~# ls -r (reverse order)
root@shadi-virtual-machine:~# dir
root@shadi-virtual-machine:~# dir --color

========================================
Creating files:
root@shadi-virtual-machine:~# touch file1 FILE1 (case sensitive)
root@shadi-virtual-machine:~# touch /root/Documents/file
root@shadi-virtual-machine:~# ls -R
- If the file exist, it will reset the timestamp of the file.
========================================

Create directories:
root@shadi-virtual-machine:~# mkdir dir1 dir2 dir3
root@shadi-virtual-machine:~# mkdir -p dir4/dir5
root@shadi-virtual-machine:~# mkdir shadi '
root@shadi-virtual-machine:~# mkdir " shadi "
root@shadi-virtual-machine:~# mkdir shadi \ alaydi
========================================

Copy files and diretories:


root@shadi-virtual-machine:~# cp file1 file2 (creates file2)
root@shadi-virtual-machine:~# cp file1 /root/Documents/
root@shadi-virtual-machine:~# cp file1 file2 file3 /root/Documents/ (last argument must be a
directory)
root@shadi-virtual-machine:~# cp -r /etc/ dir1 (copy non-empty directory)
root@shadi-virtual-machine:~# cp -r /etc/* dir1 (copy the contents of he directory)
[root@master Documents]# cp ~/file1 .
========================================

Move files and directories:


root@shadi-virtual-machine:~# mv file1 new_file1 (to rename the file1)
root@shadi-virtual-machine:~# mv file1 file2 file3 /root/Documents/ (last argument must be a
directory)
root@shadi-virtual-machine:~# mv dir1 dir2 dir3 dir4 (last argument must be a directory)
========================================
Remove files and directories:
root@shadi-virtual-machine:~# rm file1 (interactive by default for the root)
root@shadi-virtual-machine:~# rm -f file1 file2 file3 (force remove)
root@shadi-virtual-machine:~# rm -d dir1 (removes an empty directory)
root@shadi-virtual-machine:~# rmdir dir1 (removes an empty directory)
root@shadi-virtual-machine:~# rm -rf dir1 (removes a non-empty directory)
========================================

nautilus:
root@shadi-virtual-machine:~# nautilus
root@shadi-virtual-machine:~# nautilus /etc/
========================================

File globbing (wildcard) (pattern matching) (path name expansion):


root@shadi-virtual-machine:~# touch alfa bravo charlie delta echo able baker cast dog easy
root@shadi-virtual-machine:~# ls a* (Only file names beginning with "a")
root@shadi-virtual-machine:~# ls *a (Only file names ending with "a")
root@shadi-virtual-machine:~# rm -f a*
root@shadi-virtual-machine:~# ls *a* (Only file names containing "a")
root@shadi-virtual-machine:~# ls [!a]* (Only file names where first character is not "a")
root@shadi-virtual-machine:~# ls [ac]*
root@shadi-virtual-machine:~# ls ????
root@shadi-virtual-machine:~# ls ?????
root@shadi-virtual-machine:~# touch file1 file2 file3 file4 file11 file12 file111 filea fileb fileab
fa fab fabc
root@shadi-virtual-machine:~# ls f?
root@shadi-virtual-machine:~# ls f??
root@shadi-virtual-machine:~# ls file[a-c]
root@shadi-virtual-machine:~# ls file[^a-c]
root@shadi-virtual-machine:~# echo ~abeer
==============================================

Variable substitution:
root@shadi-virtual-machine:~# x=5
root@shadi-virtual-machine:~# echo x
root@shadi-virtual-machine:~# echo $x (The value of variable x)

Command substitution:
root@shadi-virtual-machine:~# echo "Today is $(date)"

Arithmatic substitution:
root@shadi-virtual-machine:~# echo "Sum of 1 plus 2 is $[1+2]"
root@shadi-virtual-machine:~# echo "Sum of 1 plus 2 is $((1+2))"

Lab Work Practice:

You might also like