0% found this document useful (0 votes)
0 views

File Managements Commands

The document outlines various file management commands in Linux, including commands for checking disk usage (df, du), comparing files (diff), and manipulating files (cat, cp, mv, rm). It also covers directory operations, file viewing and editing commands, file properties, and file searching techniques. Additionally, it provides safety precautions and alternative methods for deleting directories, along with common issues and their solutions.

Uploaded by

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

File Managements Commands

The document outlines various file management commands in Linux, including commands for checking disk usage (df, du), comparing files (diff), and manipulating files (cat, cp, mv, rm). It also covers directory operations, file viewing and editing commands, file properties, and file searching techniques. Additionally, it provides safety precautions and alternative methods for deleting directories, along with common issues and their solutions.

Uploaded by

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

File Managements Commands

commands

df=> means disk free it's used to print the used and the available size

it accepts options like df -h

du => means disk used -it's use to print the disk used by file and display where they are located
at

diff => it compares two file and determine their size, that is compare files line by line

e.g. your 1st needs to have two files to be able to compare them, if you don’t have a file to
compare to you can create one for this test.

"diff excercise exercise.bak" which are two separate files to be compared

options that can be used by the diff command are:

diff -y exercise exercise.bak

cat => can also be used to create a content(texts) to a file by using cat > filename

notice when you want to append(update) the previous file you should make use of the cat ">>"
instead of the ">" command they will overwrite what you have in the file already

e.g cat >>exercise. to append to an old file when done appending(writing) use ctrl + D to save
your file

you can verify the file written using ‘cat filename’ to display the content in the file

cp => to copy file from on directory to another

e.g. cp myfile ~/Documents/ this copies the file from the current folder or directory to another
which is the Documents directory of the home.

find => it's used to find specified file in a specified location

e.g. find /etc -name hostname

find /etc -name "*.log"

locate => is just like the find command that let's you locate a file, it goes through the system to
grab and output the files locations

e.g. locate filename

locate ivona.conf
Basic File Commands
- List Files: ls - list files in a directory. Use ls -l for detailed listing and ls -a to include hidden files.

- Copy Files: cp - copy files and directories. Use cp -r to copy directories recursively.

- Move Files: mv - move or rename files and directories.

- Remove Files: rm - delete files and directories. Use rm -r to delete directories recursively and
rm -f to force deletion.

Directory Operations
- Change Directory: cd - navigate between directories. Use cd .. to move up a directory and cd ~
to return to the home directory.

- Make Directory: mkdir - create new directories. Use mkdir -p to create parent directories if
they don't exist.

- Remove Directory: rmdir - delete empty directories.

File Viewing Commands


- Display File Contents: cat - display the contents of a file.

- View Text Files: less or more - view text files page by page.

- Head and Tail: head and tail - display the beginning or end of a file.

File Editing Commands


- Vim: vim - a popular command-line text editor.

- Emacs: emacs - another popular text editor.

File Properties Commands


- File Timestamps: touch - change file timestamps or create new empty files.

e.g. touch myfile

- File Permissions: chmod - change file permissions.

Chmod 777 myfile


- File Ownership: chown - change file ownership.

File Searching Commands


- Find Files: find - search for files based on various criteria.

- Locate Files: locate - quickly search for files using a database.

- Which Command: which - locate executable files in the system's PATH.¹

To delete a directory that's not empty in Linux, use the rm command with the -r option, which
stands for recursive removal. This will delete the directory and all its contents, including
subdirectories and files. Here's how to do it:

- Basic Syntax: rm -r directory_name

- Force Deletion: rm -rf directory_name (use with caution, as it won't prompt for confirmation)

- Verbose Mode: rm -rv directory_name (displays the deletion process)

- Interactive Mode: rm -ri directory_name (prompts for confirmation before deleting each file or
subdirectory)

Safety Precautions:
- Be cautious when using rm -rf, especially with system directories or important files.

- Double-check the directory path and contents before deletion to avoid accidental data loss.

- Consider using rm -ri for interactive deletion, which prompts for confirmation before deleting
each file or subdirectory.¹

Alternative Methods:
- Using a File Manager: You can also delete directories using a file manager like Nautilus in
Ubuntu. Simply select the directory and press Delete or right-click and choose "Move to Trash".

- Checking File System: If you encounter issues, try running fsck (File System Consistency Check)
to resolve file system errors.²

Common Issues and Solutions:


- Permission Denied: Use sudo before the rm command, like sudo rm -rf directory_name.-
Directory Being Used: Close any applications or processes using the directory, or try unmounting
it before deletion.

You might also like