Most used Linux commands

Discover essential Linux commands, including SSH connections, file transfers, using curl, and working with text editors like Nano and Vi. Learn how to manage users, check system resources, and zip/unzip files effectively. Enhance your Linux skills with our comprehensive guide on the most used Linux commands.

File and Directory Management

Manage files and directories efficiently using these commands:

List Directory Contents: ls

Detailed listing

ls -l

Include hidden files.

ls -a

Change Directory: cd

Navigate to a specific directory.

cd /path/to/directory 

Print Working Directory: pwd

Shows the current directory.

pwd

Copy Files or Directories: cp

Copy file1 to file2

cp file1 file2

Copy directories recursively.

cp -r dir1 dir2

Move or Rename Files:

Move file1

mv file1 /path/to/destination

Rename a file or directory

mv oldname newname

Remove Files or Directories:

Remove a file

rm file

Remove a directory and its contents recursively.

rm -r dir

Create a New Directory:

mkdir newdir

Remove an Empty Directory:

rmdir emptydir

Remove a Directory with its Content:

rmdir  -r dir

File Permissions and Ownership

Control access to files and directories with these commands:

Change File Permissions:

Set permissions (read/write/execute for owner, read/execute for group and others)

chmod 755 file

Change File Owner and Group:

chown user:group file

Make current user to own a file/directory

chown $USER:$USER file/direcctory

Zipping and Unzipping Files

Manage compressed files with the following commands:

Zip a File or Directory:

zip -r archive_name.zip /path/to/directory_or_file

Unzip a File:

unzip archive_name.zip

Package Management

Manage software packages with these commands: (apt- for Ubuntu or Debian, yum for Red Hat and dnf for Fedora, in this example I have used Ubuntu)

Update Package List:

sudo apt update

Upgrade Installed Packages:

sudo apt upgrade

Install a New Package:

sudo apt install package_name

Remove a Package:

sudo apt remove package_name

Remove Unnecessary Packages:

sudo apt autoremove

System Monitoring and Management

Monitor and manage system resources using these commands:

Display Real-Time System Processes:

top

Interactive Process Viewer:

htop #(requires installation)

Display Disk Space Usage:

df -h #for a human-readable format.

Display Disk Usage of Files and Directories:

du -sh /path/to/dir #for a human-readable summary.

Display Memory Usage:

free -h #for a human-readable format.

Report a Snapshot of Current Processes:

ps aux

Terminate Processes:

Terminate a process by its Process ID.

    kill PID

    Terminate all processes with the specified name.

    killall process_name 

    Restart the System:

    reboot

    Shut Down or Restart the System:

    Shut down immediately.

    shutdown now

    Shutdown immediately.

    shutdown -r now

    Network Management

    Configure and manage network settings with these commands:

    Show IP Addresses and Network Interfaces:

    ip addr

    Check Connectivity to Another Host:

    ping hostname_or_ip

    Investigate Sockets:

    Display TCP/UDP listening ports.

    ss -tuln

    User and Group Management

    Create and manage users and groups with the following commands:

    Create a Normal User:

    sudo adduser newusername

    Create a Sudo User:

    sudo adduser newusername
    sudo usermod -aG sudo newusername

    System Information

    Retrieve system details with these commands:

    Print System Information:

    uname -a

    Show Ubuntu Version Information:

    lsb_release -a

    Basic Working with the Nano Editor

    Edit text files with Nano, a simple command-line text editor:

    Open a File:

    nano filename

    Save and Exit: Press Ctrl + O to save, then Ctrl + X to exit.

    Exit Without Saving: Press Ctrl + X, then N to discard changes.

    Basic Working with the Vi Editor

    Edit text files with Vi (or Vim), a powerful text editor:

    Open a File:

    vi filename

    Switch to Insert Mode: Press i to start editing.

    Save and Exit: Press Esc, type :wq, and press Enter.

    Exit Without Saving: Press Esc, type :q!, and press Enter.

    Installing and Using curl

    Transfer data with curl, a versatile command-line tool:

    Install curl:

    sudo apt update
    sudo apt install curl

    Fetch a URL:

    curl http://example.com

    Download a File:

    curl -O http://example.com/file

    Using wget

    Download files from the web with wget:

    Install wget:

    sudo apt update
    sudo apt install wget

    Download a File:

    wget http://example.com/file

    Download a File with a Different Name:

    wget -O newfilename http://example.com/file

    SSH Connection to a Server

    Securely access remote servers using SSH:

    Using a Password:

    ssh username@hostname_or_ip

    Using an SSH Key File:

    ssh -i /path/to/keyfile username@hostname_or_ip

    Uploading and Downloading Files via SSH

    Transfer files securely between your local system and a remote server:

    Upload a File:

    scp /local/path/to/file username@hostname_or_ip:/remote/path

    Download a File:

    scp username@hostname_or_ip:/remote/path/to/file /local/path

    These are a few linux commands, if you get sudo prtmission error for a command, then just add sudo befor the command.