0% found this document useful (0 votes)
50 views4 pages

File and Directory Management LINUX

Uploaded by

astigansh15
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)
50 views4 pages

File and Directory Management LINUX

Uploaded by

astigansh15
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 and Directory Management

 ls: List files and directories in the current directory.


Example: ls -l (Displays detailed information about files and directories.)
 cd: Change the current directory.
Example: cd /home/user/Documents (Switch to the Documents directory.)
 pwd: Print the current working directory.
Example: pwd (Shows the current directory path.)
 mkdir: Create a new directory.
Example: mkdir new_folder (Creates a folder named "new_folder.")
 rmdir: Remove an empty directory.
Example: rmdir old_folder (Deletes the empty "old_folder" directory.)
 touch: Create an empty file.
Example: touch file.txt (Creates a file named "file.txt.")
 cp: Copy files or directories.
Example: cp file.txt /home/user/backup/ (Copies "file.txt" to the "backup"
folder.)
 mv: Move or rename files or directories.
Example: mv file.txt renamed_file.txt (Renames "file.txt" to "renamed_file.txt.")
 rm: Delete files or directories.
Example: rm file.txt (Deletes the file "file.txt.")
 find: Search for files or directories.
Example: find /home -name "*.txt" (Searches for all .txt files in the /home
directory.)
 tree: Display directories and files in a tree-like structure.
Example: tree /home/user (Shows the directory structure of /home/user.)

File Viewing and Editing

 cat:Display the contents of a file.


Example: cat file.txt (Shows the content of "file.txt.")
 less: View the contents of a file one screen at a time.
Example: less large_file.txt (Opens "large_file.txt" for paginated viewing.)
 more: Similar to less, but with fewer features.
Example: more file.txt (Displays "file.txt" content page by page.)
 head: Display the first few lines of a file.
Example: head -n 5 file.txt (Shows the first 5 lines of "file.txt.")
 tail: Display the last few lines of a file.
Example: tail -n 5 file.txt (Shows the last 5 lines of "file.txt.")
 nano: Simple command-line text editor.
Example: nano file.txt (Opens "file.txt" for editing in Nano editor.)
 vim:Advanced text editor.
Example: vim file.txt (Opens "file.txt" for editing in Vim editor.)
 echo: Print text to the screen or write to a file.
Example: echo "Hello World" > hello.txt (Writes "Hello World" into "hello.txt.")

File Permissions and Ownership

 chmod: Change file permissions.


Example: chmod 755 script.sh (Sets permissions to read, write, and execute for the
owner, and read/execute for others.)
 chown: Change file ownership.
Example: chown user:user file.txt (Changes the owner and group of "file.txt" to
"user.")
 chgrp: Change file group ownership.
Example: chgrp group_name file.txt (Changes the group ownership of "file.txt.")
 umask: Set default permissions for new files.
Example: umask 022 (Sets default permissions to allow others to read but not write.)

Disk and Filesystem Management

 df: Show disk space usage.


Example: df -h (Displays disk usage in human-readable format.)
 du: Show directory or file size.
Example: du -sh folder_name (Shows the size of the folder "folder_name.")
 mount: Mount a filesystem.
Example: mount /dev/sdb1 /mnt/usb (Mounts the device "sdb1" to the /mnt/usb
directory.)
 umount: Unmount a filesystem.
Example: umount /mnt/usb (Unmounts the /mnt/usb directory.)
 fsck: Check and repair a filesystem.
Example: fsck /dev/sda1 (Checks and repairs the filesystem on "sda1.")
 mkfs: Create a new filesystem on a partition.
Example: mkfs.ext4 /dev/sda1 (Formats the "sda1" partition as ext4.)

Process Management
 ps: List running processes.
Example: ps aux (Displays a detailed list of all processes.)
 top: Display running processes in real-time.
Example: top (Shows system resource usage in real time.)
 htop: Similar to top with a better interface (needs installation).
Example: htop (Launches an interactive process viewer.)
 kill: Terminate a process by its PID.
Example: kill 1234 (Terminates the process with PID 1234.)
 killall: Terminate processes by name.
Example: killall firefox (Closes all instances of Firefox.)
 bg: Resume a job in the background.
Example: bg %1 (Resumes job number 1 in the background.)
 fg: Resume a job in the foreground.
Example: fg %1 (Resumes job number 1 in the foreground.)
 jobs: List active jobs.
Example: jobs (Displays background jobs.)

Networking

 ping: Test connectivity to a host.


Example: ping google.com (Tests connectivity to "google.com.")
 curl: Transfer data from or to a server.
Example: curl https://example.com (Fetches the content of "example.com.")
 wget: Download files from the internet.
Example: wget https://example.com/file.zip (Downloads "file.zip.")
 ifconfig: Show or configure network interfaces (deprecated, use ip).
Example: ifconfig (Displays network interface information.)
 ip: Show/manipulate network interfaces.
Example: ip addr show (Displays IP address information.)
 netstat: Display network connections (deprecated, use ss).
Example: netstat -tuln (Lists open ports and listening services.)
 ss: Display network statistics and connections.
Example: ss -tuln (Displays listening ports and connections.)

User Management

 whoami: Display the current user.


Example: whoami (Displays your username.)
 who: Show who is logged into the system.
Example: who (Lists all logged-in users.)
 id: Display user ID and group ID.
Example: id (Displays your user and group IDs.)
 adduser: Add a new user (or useradd on some systems).
Example: adduser newuser (Adds a new user named "newuser.")
 passwd: Change a user's password.
Example: passwd (Changes the current user's password.)
 su: Switch to another user account.
Example: su root (Switches to the root user.)
 sudo: Run a command as a superuser.
Example: sudo apt update (Runs the command as root.)

Let me know if you'd like more examples or details for any specific command!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy