Administering Networking OS — Working With Files and Directories #6
College Online Material
Published in
3 min readMay 3, 2021
Working With Files and Directories
Files and Directories
- File contains data (text, graphics, etc)
- Directories store filenames
- Top-level directory is
/
(root)
Directory Path
- Direction to a specific file or dir.
- The direction was given from
/
are called “absolute” paths - The direction given from the current directory is called “relative” paths
The Home Directory
- Each user has a home directory
- Typically
/home/bob
for a user named bob - A place to store your own files
- Normally, users can’t access the home dir. of other users
~
symbolizes the home dir.
Current Directory
- The directory that your shell is currently in
- Can be displayed with the
pwd
command
Changing Directories
- Use
cd
command - With no arguments, take you to your home dir.
~bob
would refer to bob’s home dir.
Absolute Vs. Relative Pathnames
- Absolute pathnames always provide directions from the root directory
- Relative pathnames always provide direction from the current directory
- To refer to one dir. above current dir, use the
..
char - To refer to the current dir, use the
.
char
Manipulating Files
Listing Files in A Directory
- List files with the
ls
command - The different file type may be highlighted by colored filenames
- The display of filenames in color is the result of the
— color
option
Common ls Options
- Example
$ ls -al
-a
display all files, including hidden files
-l
long display listing
-h
Give file sizes in human-readable sizes
-R
Recursive listing
-S
Sort output based on file size
-t
Sort output based on modification time
-d
Don’t display directory contents
Copying Files
- The cp command copies files
cp [source] [destination]
–v
option to display copy process
–i
to prompt overwrites
–n
to avoid overwrites
–r
to copy directory structures
Moving Files
- The
mv
command files
mv [source] [destination]
- The
mv
command also is used to rename files - The supported option that works the same as the cp command
–v
option to display copy process
–i
to prompt overwrites
–n
to avoid overwrites
Creating Files
- Editors can be used to create files
- Use
touch
command to create an empty file - The
touch
command all updates the modification timestamp of a file
$ touch a.txt
$ touch auth.cfg a.txt b.pdf
Removing Files
- The
rm
command is used to delete files - File deletion is permanent
- Use
-i
to avoid accidental deletion when using globs - Delete dir. with the
-r
option orrmdir
if the directory is completely empty
$ rmdir anime
$ rm -rf passwd
Making Directories
- Use
mkdir
command to create directories
$ mkdir anime