0% found this document useful (0 votes)
24 views3 pages

OSY8

22516 osy practical no 8

Uploaded by

omkokate555
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)
24 views3 pages

OSY8

22516 osy practical no 8

Uploaded by

omkokate555
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/ 3

Here are the file directory manipulation commands in Linux, including their theory and examples.

For Windows, alternate commands are provided at the end.

1. rm (Remove)

Theory:
The rm command is used to remove (delete) files or directories. By default, rm only deletes files. If
you want to delete directories, you must use the -r (recursive) option.

Usage:

rm file_name # Deletes a file

rm -r directory_name # Deletes a directory and its contents

rm -f file_name # Force delete a file without confirmation

2. mv (Move)

Theory:
The mv command is used to move or rename files and directories. When used to rename, it changes
the file name. When used to move, it moves the file from one location to another.

Usage:

mv old_file_name new_file_name # Renames a file

mv file_name /path/to/directory/ # Moves file to another directory

3. cp (Copy)

Theory:
The cp command is used to copy files or directories. By default, it copies the contents of a file to a
new file. To copy directories, the -r option is used to copy recursively.

Usage:

cp source_file destination_file # Copies a file

cp -r source_directory destination_directory # Copies a directory

cp -i source_file destination_file # Prompts before overwriting

4. join

Theory:
The join command is used to join two files based on a common field. It works by matching lines from
the two files based on a key field and combines them into a single output.

Usage:

join file1 file2 # Joins file1 and file2 on their common field

5. split

Theory:
The split command is used to split a large file into smaller files. By default, it splits files into chunks of
1000 lines, but you can specify the size.
Usage:

split large_file # Splits large_file into smaller parts

split -l 1000 large_file new_prefix # Splits by lines, with a custom prefix for output files

6. cat (Concatenate)

Theory:
The cat command is used to display the contents of a file, combine multiple files, or create new files.
It can be used to quickly view file contents.

Usage:

cat file_name # Displays the content of a file

cat file1 file2 > combined_file # Concatenates file1 and file2 into combined_file

7. head

Theory:
The head command is used to display the first few lines of a file (by default, the first 10 lines).

Usage:

head file_name # Displays the first 10 lines of a file

head -n 20 file_name # Displays the first 20 lines of a file

8. tail

Theory:
The tail command is used to display the last few lines of a file (by default, the last 10 lines). It is often
used to view logs in real time by using the -f option.

Usage:

tail file_name # Displays the last 10 lines of a file

tail -n 20 file_name # Displays the last 20 lines of a file

tail -f file_name # Continuously monitors the file for new content

9. touch

Theory:
The touch command is used to create empty files or update the timestamp of existing files. If the file
doesn’t exist, it will create an empty file.

Usage:

touch new_file_name # Creates an empty file

touch existing_file # Updates the timestamp of an existing file

Alternate Commands for Windows:


For Windows, the equivalent file manipulation commands are:

• rm → del: Deletes files in Windows.

• mv → move: Moves or renames files in Windows.

• cp → copy: Copies files in Windows.

• join → Not directly available in Windows, but can use findstr or PowerShell scripts.

• split → fsutil: Windows does not have a direct split command, but fsutil can be used to
manipulate file sizes.

• cat → type: Displays the contents of a file in Windows.

• head → Not directly available in Windows, but PowerShell can be used for similar
functionality (e.g., Select-Object -First 10).

• tail → get-content: PowerShell’s Get-Content cmdlet with the -Tail option simulates tail.

• touch → echo.: Create an empty file using echo. > filename.

Let me know if you need any further explanation!

You might also like