Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Directories and File Handling Commands

Uploaded by

das9434945589
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Directories and File Handling Commands

Uploaded by

das9434945589
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Directory & File Handling Commands

NAVIGATING THE FILE


SYSTEM
cd (Change Directory)
• Use the 'cd' command to navigate to a different directory.
• Example: 'cd Documents' will change the current directory to th 'Documents' directory.
pwd (Print Working Directory)
• Use the 'pwd' command to display the current working directory.
• Example: 'pwd' will show the current directory path.
ls (List)
• Use the 'ls' command to list the files and directories in the current directory.
• Example: 'ls' will display all the files and directories in the current directory.
COPYING AND MOVING FILES
Copying Files with 'cp’ Moving Files with 'mv’
• The 'cp' command is used to copy files and • The 'mv' command is used to move files
directories. and directories.
• Syntax: cp [options] source destination • Syntax: mv [options] source destination
• Example: cp file1.txt file2.txt • Example: mv file1.txt directory/
• This command will create a copy of • This command will move file1.txt to the
file1.txt named file2.txt in the current directory specified.
directory.
CREATING AND DELETING
DIRECTORIES
Creating Directories
• The 'mkdir' command is used to create directories in Unix-OS.
• Syntax: mkdir [directory_name]
• Example: mkdir new_directory
Deleting Directories
• The 'rmdir' command is used to delete empty directories in Unix-OS.
• Syntax: rmdir [directory_name]
• Example: rmdir directory_to_delete
Note: The 'rmdir' command can only delete empty directories. To delete directories with
contents, use the 'rm' command with the '-r' flag.
FINDING FILES
find grep
▪ The 'find' command is used to search for ▪ The 'grep' command is used to search for
files and directories in a directory specific patterns or regular expressions in
hierarchy based on various criteria, such as files.
name, size, and modification time.
RENAMING FILES AND
DIRECTORIES
mv
• The 'mv' command is used to rename files and directories. It can also be used to move files and
directories to a different location.
• Syntax: mv [source_file_name(s)] [Destination_file_name]
• Example: mv file1.txt file2.txt
ARCHIVING AND
COMPRESSING FILES
Archiving Files with Tar • Extracting Files from Tar Archive
• The 'tar' command is used to create an • To extract files from a tar archive, use the
archive file that contains multiple files and 'tar' command with the 'x' option.
directories.
• Syntax: tar -xvf archive.tar
• Syntax: tar -cvf archive.tar file1 file2
• Example: tar -xvf backup.tar
directory1
• Example: tar -cvf backup.tar file1.txt
directory1
LISTING FILES AND
DIRECTORIES
▪ When working with Unix-OS, there are several commands available to list files and
directories. The most commonly used command is 'ls', which stands for 'list'. This command
displays the names of files and directories in the current directory.

Option' Description
'ls' Lists files and directories in the current directory

'ls -l' Lists files and directories in long format, including


additional details such as permissions, owner, size, and
modification date

'ls -a' Lists all files and directories, including hidden files and
directories
'ls -lh' Lists files and directories in long format with
human-readable file sizes
'ls -R' Lists files and directories recursively, including
subdirectories
CHANGING FILE
PERMISSIONS
chmod
▪ The 'chmod' command is used to change the permissions of a file or directory in Unix-OS.
REFERENCES
Websites
• ist.njit.edu
• geeksforgeeks.org
• cyberciti.biz
• tutorialshut.com

You might also like