Unix - Important Commands with Usage

Unix - Important Commands with Usage

1. File and Directory Management Commands

ls

  • Usage: Lists files and directories.
  • Syntax: ls [options] [path]
  • Example:ls: List files in the current directory.ls -l: List files in long format with details like permissions, owner, size, etc.ls -a: List all files, including hidden files.

cd

  • Usage: Changes the current directory.
  • Syntax: cd [directory]
  • Example:cd /home/user: Change to the specified directory.cd ..: Move to the parent directory.cd ~: Move to the home directory.

pwd

  • Usage: Prints the current working directory.
  • Syntax: pwd
  • Example: pwd

mkdir

  • Usage: Creates a new directory.
  • Syntax: mkdir [options] directory_name
  • Example:mkdir my_folder: Creates a directory named my_folder.mkdir -p dir1/dir2: Creates nested directories.

rm

  • Usage: Removes files or directories.
  • Syntax: rm [options] file_or_directory
  • Example:rm file.txt: Deletes file.txt.rm -r folder: Deletes a directory and its contents recursively.

rmdir

  • Usage: Removes an empty directory.
  • Syntax: rmdir directory_name
  • Example: rmdir empty_folder

cp

  • Usage: Copies files or directories.
  • Syntax: cp [options] source destination
  • Example:cp file1.txt file2.txt: Copies file1.txt to file2.txt.cp -r folder1 folder2: Copies folder1 to folder2 recursively.

mv

  • Usage: Moves or renames files or directories.
  • Syntax: mv [options] source destination
  • Example:mv file1.txt file2.txt: Renames or moves file1.txt to file2.txt.

2. File Viewing Commands

cat

  • Usage: Displays the content of a file.
  • Syntax: cat [options] file
  • Example:cat file.txt: Displays the content of file.txt.cat file1.txt file2.txt > merged.txt: Concatenates two files into a new file.

more

  • Usage: Displays file content page by page.
  • Syntax: more [file]
  • Example: more file.txt

less

  • Usage: Displays file content, allowing navigation.
  • Syntax: less [file]
  • Example: less file.txt

head

  • Usage: Displays the first few lines of a file.
  • Syntax: head [options] file
  • Example: head -n 10 file.txt (Shows the first 10 lines).

tail

  • Usage: Displays the last few lines of a file.
  • Syntax: tail [options] file
  • Example: tail -n 10 file.txt (Shows the last 10 lines).

3. File Permission and Ownership Commands

chmod

  • Usage: Changes file permissions.
  • Syntax: chmod [options] mode file
  • Example:chmod 755 file.txt: Sets read, write, and execute for owner; read and execute for group and others.

chown

  • Usage: Changes file ownership.
  • Syntax: chown [owner][:group] file
  • Example: chown user:group file.txt

chgrp

  • Usage: Changes group ownership.
  • Syntax: chgrp [group] file
  • Example: chgrp group file.txt

4. Process Management Commands

ps

  • Usage: Displays information about active processes.
  • Syntax: ps [options]
  • Example:ps: Displays processes for the current shell.ps -ef: Displays all running processes.

top

  • Usage: Shows real-time processes and system resource usage.
  • Syntax: top

kill

  • Usage: Terminates a process by PID.
  • Syntax: kill [signal] PID
  • Example: kill -9 12345

jobs

  • Usage: Lists background jobs.
  • Syntax: jobs

fg

  • Usage: Brings a background job to the foreground.
  • Syntax: fg [job_id]

bg

  • Usage: Resumes a suspended job in the background.
  • Syntax: bg [job_id]

5. Networking Commands

ping

  • Usage: Checks connectivity to a host.
  • Syntax: ping [options] host
  • Example: ping google.com

netstat

  • Usage: Displays network connections and statistics.
  • Syntax: netstat [options]

curl

  • Usage: Transfers data from or to a server.
  • Syntax: curl [options] URL
  • Example: curl https://example.com

wget

  • Usage: Downloads files from the web.
  • Syntax: wget [options] URL
  • Example: wget https://example.com/file.txt

scp

  • Usage: Copies files between hosts.
  • Syntax: scp [options] source destination
  • Example: scp file.txt user@host:/path/to/destination

ssh

  • Usage: Logs into a remote machine securely.
  • Syntax: ssh user@host
  • Example: ssh [email protected]

6. Disk Usage Commands

df

  • Usage: Displays disk space usage.
  • Syntax: df [options]
  • Example: df -h (Shows human-readable format).

du

  • Usage: Displays directory or file space usage.
  • Syntax: du [options] [path]
  • Example: du -sh folder/

7. Search and Filter Commands

grep

  • Usage: Searches for a pattern in files.
  • Syntax: grep [options] pattern file
  • Example:grep 'hello' file.txt: Searches for ‘hello’ in file.txt.grep -r 'error' /var/logs: Searches recursively for ‘error’ in /var/logs.

find

  • Usage: Searches for files and directories.
  • Syntax: find [path] [options]
  • Example:find . -name "*.txt": Finds all .txt files in the current directory.find /home -size +100M: Finds files larger than 100MB.

awk

  • Usage: Processes and analyzes text.
  • Syntax: awk 'pattern {action}' file
  • Example: awk '{print $1}' file.txt: Prints the first column of a file.

sed

  • Usage: Edits text in a file or stream.
  • Syntax: sed 'script' file
  • Example: sed 's/old/new/g' file.txt: Replaces ‘old’ with ‘new’.

8. Archiving and Compression Commands

tar

  • Usage: Archives files and directories.
  • Syntax: tar [options] archive_name file_or_directory
  • Example: tar -cvf archive.tar folder

gzip

  • Usage: Compresses files.
  • Syntax: gzip [file]
  • Example: gzip file.txt

unzip

  • Usage: Extracts ZIP files.
  • Syntax: unzip file.zip


This list provides an essential toolkit for working effectively in a Unix environment. Mastering these commands can significantly enhance your productivity and proficiency!

Hope this document is helpful. If you are studying Data Engineering and want to understand the concepts in detail, you can consider downloading 30+ free study materials from below link.

Download 30+ Spark Study Material: https://codeinspark.com/download-center/

要查看或添加评论,请登录

Soutir Sen的更多文章

  • Spark Optimization - Serialization

    Spark Optimization - Serialization

    1. Introduction to Spark Serialization Serialization is the process of converting an object into a byte stream so that…

  • PySpark – Dynamic Partition Pruning

    PySpark – Dynamic Partition Pruning

    Introduction to Partition Pruning Partition pruning in PySpark (and in general in distributed computing) is a key…

    1 条评论
  • Pyspark - Adaptive Query Execution(AQE)

    Pyspark - Adaptive Query Execution(AQE)

    Adaptive Query Execution (AQE) is an optimization feature introduced in Spark 3.0 to enhance the performance of query…

    4 条评论
  • Spark UDF - Complete Guide

    Spark UDF - Complete Guide

    1. Introduction to PySpark UDFs What are UDFs? A User Defined Function (UDF) is a way to extend the built-in functions…

  • Spark Optimization - Broadcast Variable

    Spark Optimization - Broadcast Variable

    1. Introduction to Broadcast Variables in Spark Apache Spark is a powerful distributed computing system that can handle…

  • Apache Kafka – Complete Guide

    Apache Kafka – Complete Guide

    Apache Kafka is an open-source distributed event streaming platform capable of handling trillions of events a day. It…

    1 条评论
  • SparkSession vs SparkContext - Complete Guide

    SparkSession vs SparkContext - Complete Guide

    SparkSession vs SparkContext Apache Spark provides two primary entry points for interacting with its functionality: and…

  • Shell Script: A Comprehensive Guide

    Shell Script: A Comprehensive Guide

    Introduction Shell scripting is a powerful way to automate tasks, manage system operations, and enhance productivity in…

  • Pandas Dataframe - All Operations

    Pandas Dataframe - All Operations

    Introduction to Pandas DataFrame Pandas is a powerful Python library for data analysis and manipulation. A DataFrame is…

  • Git - All Commands

    Git - All Commands

    1. Basic Git Commands 1.

社区洞察