3 Basic Commands and Simple Shell Scripts Once you have your first Red Hat Enterprise Linux rhel


Listing, creating, copying, and moving files, directories



Download 1.85 Mb.
View original pdf
Page19/67
Date26.02.2024
Size1.85 Mb.
#63678
1   ...   15   16   17   18   19   20   21   22   ...   67
Pablo Iranzo Gómez, Pedro Ibáñez Requena, Miguel Pérez Colino, Scott McCarty - Red Hat Enterprise Linux 9 Administration-Packt Publishing (2022) -chap 3 82 - 180
Listing, creating, copying, and moving files, directories,
links, and hard links
It is important to know how to manage files and directories in a system from the command line. It will serve as the basis for managing and copying important data, such as configuration files or data files.

Basic Commands and Simple Shell Scripts
84
Directories
Let’s start by creating a directory to keep some working files. We can do so by running mkdir, short for make directory”:
[user@rhel-instance
]$ mkdir mydir

[user@rhel-instance
]$ ls -l

total 0
drwxrwxr-x. 2 user user 6 Feb 13 19:53 mydir
Folders can be deleted with the rmdir command, short for remove directory”:
[user@rhel-instance
]$ ls -l

total 0
drwxrwxr-x. 2 user user 6 Feb 13 19:53 mydir
[user@rhel-instance
]$ mkdir deleteme

[user@rhel-instance
]$ ls -l

total 0
drwxrwxr-x. 2 user user 6 Feb 13 20:15 deleteme
drwxrwxr-x. 2 user user 6 Feb 13 19:53 mydir
[user@rhel-instance
]$ rmdir deleteme

[user@rhel-instance
]$ ls -l

total 0
drwxrwxr-x. 2 user user 6 Feb 13 19:53 mydir
However, rmdir will only delete empty directories:
[user@rhel-instance
]$ ls etc >
/mydir/etc-files.txt

[user@rhel-instance
]$ rmdir mydir

rmdir: failed to remove 'mydir': Directory not empty
How can we delete a directory and all the other files and directories it contains using the remove (rm) command First, let’s just create and remove a single file, var-files.txt:
[user@rhel-instance
]$ ls var >
/var-files.txt

[user@rhel-instance
]$ ls -l var-files.txt

-rw-rw-r--. 1 user user 109 Feb 13 15:31 var-files.txt
[user@rhel-instance
]$ rm var-files.txt


Download 1.85 Mb.

Share with your friends:
1   ...   15   16   17   18   19   20   21   22   ...   67




The database is protected by copyright ©ininet.org 2024
send message

    Main page