0% found this document useful (0 votes)
29 views6 pages

System Administration

Uploaded by

Sassi Lali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views6 pages

System Administration

Uploaded by

Sassi Lali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Significant Red Hat Enterprise Linux Directories

Chapter 3. Manage Files from the


/boot Files to start the boot process.
Command Line
The File-system Hierarchy /dev
Special device files that the system uses to access
hardware.
The Linux system stores all files on file systems, which
are organized into a single inverted tree known as a file- /etc System-specific configuration files.

system hierarchy. This hierarchy is an inverted tree


because the tree root is at the top, and the branches of /home
Home directory, where regular users store their data and
configuration files.
directories and subdirectories stretch below the root.
/root Home directory for the administrative superuser, root.

... Runtime data for processes that started since the last
/run
boot.

/temp A world-writable space for temporary files.

Installed software, shared libraries, including files, and


Static content remains unchanged until explicitly read-only program data. Significant subdirectories in the
/usr directory include the following commands:
edited or reconfigured. /usr /usr/bin: User commands
Dynamic or variable content might be modified or /usr/sbin: System administration commands
appended by active processes. /usr/local: Locally customized software

Persistent content remains after a reboot, such as


configuration settings.
Runtime content from a process or from the system is /var
System-specific variable data should persist between
boots. Files that dynamically change, such as databases...
deleted on reboot.
Specify Files by Name 2-Relative Paths:
Absolute Paths and Relative Paths A relative path gives directions to a file or folder
=>The path of a file or directory specifies its based on your current location (current working
unique file-system location directory).
Absolute Paths Unlike an absolute path, which starts from the root
the exact location of the file in the file-system (/), a relative path doesn’t start with a forward
hierarchy slash. It just gives the path from where you are now.
a path name with a forward slash (/) as the first Example: If you're in /var, the path
character is an absolute path name. log/messages points to the /var/log/messages
file.
3-Case Sensitivity:
The Current Working Directory and Relative
Linux file systems (like ext4, XFS) are case-
Paths
sensitive.
1-Current Working Directory:
On non-Linux file systems (like Microsoft's NTFS or
When you open a terminal, you start in your "home
Apple's HFS+), the system might preserve the case
directory" (your personal folder).
(show it how you wrote it), but not be case-sensitive.
The current working directory is wherever you are
On these systems, FileCase.txt and filecase.txt
at the moment in the file system. As you move
around (change directories), this location would point to the same file.
changes.
Navigate Paths in the File System

$ pwd moves you up one level to the


print working directory $ cd ..
/home/user parent directory.

lists the contents of a directory


$ ls Desktop If you don't specify a directory, it lists switches you back and forth
$ cd -
Documents ... the files and folders in your current between two directories.
directory.

change directory Tilde (~) Special Character:


moves you to a different folder. The tilde (~) represents your home
absolute paths (e.g., directory. You can combine it with
$ cd Videos
/home/user/Documents) or relative $ ls -l ~ commands to interact with files in
[user@host
paths (e.g., Documents). your home directory, no matter
Videos]$ pwd
If you run cd without any arguments, it where you are in the file system.
brings you back to your home
directory (~).

The . represents "the current


The touch command updates the directory" in commands, so you can
$ touch cp file.txt
timestamp of a file. If the file doesn’t use it as a shortcut instead of typing
Videos/blockb ./file_backup.txt
exist, it creates an empty file, which is out the full path to your current
uster1.ogg
useful for practice or testing. directory

$ ls -a Files that start with a dot (.) are ls -al:


.bashrc hidden. They don’t show up in normal This command lists files in the current directory in long format (-l)
.bash_profile ls listings. and includes hidden files (-a). Hidden files are those that begin with
.config To view hidden files, use ls -a a dot (.), and the long format provides details like file permissions,
ownership, and timestamps.
Manage Files with Command-line Tools

The mkdir command creates The rm command deletes


directories files, but not directories by
You can create multiple default. To remove
directories at once by listing their directories and their
names separated by spaces. contents, use the -r option.
mkdir ProjectX rm file.txt
The -p option creates missing You can use rm -i for
parent directories if needed. interactive deletion, where it
rm -r directory_name/
(Be cautious when using -p because asks for confirmation before
it can unintentionally create deleting.
misspelled directories) Important: There is no
undelete feature in the
command line.

Copying Files and Directories


cp file1.txt The cp command copies files, and -i (interactive): Prompts you for confirmation before
file2.txt by default does not copy each removal. You will have to type y or n to confirm
target_dir/ directories unless the -r
whether you want to delete each file.
(recursive) option is used.
cp -r source_dir/ -f (force): Forces the removal of files without any
You can copy multiple files to a
target_dir/ directory by specifying the target confirmation, even if the files are write-protected. This
directory as the last argument. option also suppresses error messages.

mv oldname.txt
The mv command can both move The rmdir command
newname.txt
files to a new location and removes only empty
rename files. rmdir EmptyDir directories.
mv file.txt
path changes, but the content rm -r nonEmptyDir For non-empty directories,
destination_direc
remains unchanged. you must use rm -r.
tory/
Make Links Between Files
You can create multiple file names that point to the same file. These file names are called links.

Hard Links Symbolic Links (Soft Links)


When a hard link is created, it acts like the original file A special file that points to another file or directory.
name. =>Points to another file or directory by name. If the target is
=>Points directly to data. If a hard link is deleted, the data deleted, the link becomes a "dangling" link.
still exists as long as other hard links reference it. Use case:Use symbolic links for cross-file-system links or
Use case: Use hard links when you need multiple references when you want to link to directories.
to the same data within the same file system. Key Properties:
Key Properties: Symbolic links work across different file systems and can
Each file starts with one hard link (its original name). link to directories.
All hard links share the same inode number, When the target file is deleted, the symbolic link
permissions, ownership, timestamps, and data. remains but points to nothing (dangling link).
Deleting the original file doesn't delete the data if other Behavior:
hard links exist. Deleting a symbolic link does not affect the original file.
Hard links can only be created for regular files, not If a new file with the same name as the deleted target is
directories or special files. created, the symbolic link will point to the new file.
Hard links must be on the same file system.
Limitations:
Hard links can’t be created across different file
systems or for directories.

ln originalfile.txt hardlink.txt
ln -s /path/to/originalfile.txt symlink.txt
ls -il originalfile.txt hardlink.txt # shows same
ls -l symlink.txt # shows the link destination
inode numbers
Match File Names with Shell Expansions ~: Expands to the user's home directory.
Bash Shell Expansions: ~username: Expands to another user's
When a command is typed, Bash performs several Tilde home directory.
expansions to transform it before executing. These Expansion Example:
echo ~user: Outputs /home/user.
include:
Select files by using patterns These patterns
include wildcards Variables store values, which can be accessed
Common wildcards include: using $VARNAME or ${VARNAME}.
Variable
*: Matches any string (including zero Example:
characters).
Expansion USERNAME=operator; echo $USERNAME:
?: Matches any single character. Outputs operator.
Pathname [ABC]: any character inside the brackets.
[!abc] or [^abc]: character not inside the
Expansion Executes a command and replaces it with the
brackets.
(Globbing) [[:alpha:]]: Any alphabetic character output.
[[:alnum:]:Any alphabetic character or digit Done using $(command).
Examples: Command Example:
ls a*: Matches files starting with "a". echo Today is $(date +%A): Outputs Today
Substitution
ls *a*: Matches files containing "a". is Wednesday.
Note:An earlier form of command substitution uses
ls ????: Matches files with exactly four
backticks: `command`. Although the Bash shell still
characters. accepts this format, try to avoid it

Protecting Arguments from Expansion


Expands sets of comma-separated strings or
ranges. Backslash (\): Escapes a character to prevent its expansion.
Useful for generating patterns or creating Single quotes (' '): Prevents all expansions.
Brace multiple files. Double quotes (" "): Allows variable and command substitution but
Expansion Examples: blocks pathname expansion.
echo {Sunday,Monday}.log: Expands to Examples:
Sunday.log Monday.log. echo \$HOME: Outputs $HOME without expansion.
mkdir RHEL{7,8,9}: Creates directories RHEL7, echo "***** hostname is ${myhost} *****": Expands myhost inside the
RHEL8, RHEL9. quotes.

You might also like