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

Linux Commands

Uploaded by

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

Linux Commands

Uploaded by

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

1.

File and Directory Management Commands

ls

 ls lists files in the current directory.

ls -l

 -l shows detailed information like permissions, ownership, and file size.

cd /home/user

 cd changes the current directory.

cd ..

 cd .. moves up one directory.

pwd

 Displays the full path of the current directory.

mkdir <new_folder_name>

 It create a new directory

mkdir -p /path/to/multiple/directories

 -p creates parent directories as needed.

touch

 This Command by default creates an empty file.

cp – Copy command

cp <source_file> <destination_file>

 It copies the source file content to destination file

cp -r /path/to/source/ /path/to/destination/

 -r recursively copies directories.

mv – Move or rename command

mv <oldfile_name> <newfile_name>
 It moves the content from one file to another file

mv <file.txt> </path/to/new/location/>

 Renames or moves files and directories.

rm – Remove command

rm –f <file_name>

 It removes or deletes the files

rm -rf <directory_name>

 force remove the files & folders of directory recursively (-f force).

rmdir <empty_folder>

 Removes empty directories.

2. File Viewing and Editing

cat <file_name>

 Displays the contents of a file.

tac <file_name>

 Display file content in reverse order

less <file_name>

 View file content one screen at a time

 Use arrow keys to scroll, q to quit.

head <file_name>

 View the first 10 lines of a file

head -n 5 <file_name>

 -n specifies the number of lines to display.

tail <file_name>

 View the last 10 lines of a file

tail -n 5 <file_name>
 -n specifies the number of lines to display.

3. File Permissions and Ownership


Change file permissions

chmod 755 <file_name>

 755 grants read, write, execute for the owner, and read/execute for group and others.

chmod u+x <file_name>

 u+x adds execute permission for the owner.

chown user:group <file_name>

 Changes the owner and group of a file.

chgrp group_name <file_name>

 Changes the group ownership which is associated with a file.

4. Disk Usage and Storage

df -h

 Display disk space usage

 -h shows human-readable sizes (KB, MB, GB).

du -sh /path/to/directory/

 Estimate file space usage

 -s provides a summary, and -h shows human-readable sizes.

5. Process Management

ps

 shows the currently running process.

ps -ef

 Displays all processes running on the system.


top

 Shows the real-time, dynamic view of the running processes of a system.

kill <pid>

 Terminate a process PID

kill -9 <pid>

 -9 forces termination.

6. Networking Commands

ifconfig

 Displays the network interface information.

ping <hostname>

 Test network connection. It tests the reachability & responsiveness of the remote host.

netstat -lntp

 Displays all listening ports and connections.

ssh user@<remote_host_address>

 Securely connect to a remote machine

 Connects to a remote system via SSH.

wget <url>

 Download files from the web

curl <url>

 Downloads the content <url> and displays it in the terminal.

7. System Information

uname

 Displays kernel and system information.


hostname

 Shows the name of the system host.

hostid

 shows the host id of the system assigned by the OS

uptime

 Shows the elapsed time duration since the machine logged in.

whoami

 Shows the currently logged-in username of the terminal.

last

 Displays a list of recent logins.

date

 Shows the current date and time in UTC format.

history

 lists all the commands executed until now

8. Package Management

Package management for RedHat

sudo dnf update

 Refresh the list of available packages.

 Check for newer versions of installed software.

sudo dnf install <package_name>

 Installing the packages

sudo dnf remove <package_name>

 removing the package


9. Service Management

sudo systemctl start <service name>

 To start the service

sudo systemctl enable <service name>

 To enable the service

sudo systemctl disable <service name>

 To disable the service

sudo systemctl status <service name>

 check the status of the service

sudo systemctl restart <service name>

 To restart a service

You might also like