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

Some Importantes Commands Linux

The document provides examples of 20 common Linux commands and their usage. It lists 5 examples for each command, including ls to list directory contents, cd to change directories, pwd to print the working directory, and cp to copy files. Other commands covered are mv to move files, rm to remove files, mkdir and rmdir to create and remove directories, and touch to create empty files.

Uploaded by

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

Some Importantes Commands Linux

The document provides examples of 20 common Linux commands and their usage. It lists 5 examples for each command, including ls to list directory contents, cd to change directories, pwd to print the working directory, and cp to copy files. Other commands covered are mv to move files, rm to remove files, mkdir and rmdir to create and remove directories, and touch to create empty files.

Uploaded by

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

Here are five examples for each of the 20 Linux

commands:
ls - List directory contents
 ls: List files and directories in the current directory.
 ls -l: Detailed list with file permissions, owners, and sizes.
 ls -a: List all files, including hidden ones.
 ls -lh: Human-readable file sizes.
 ls -R: List subdirectories recursively.

cd - Change directory
 cd Documents: Change to the 'Documents' directory.
 cd /usr/local: Change to the '/usr/local' directory.
 cd ~: Change to the home directory.
 cd -: Switch to the previous working directory.
 cd ..: Move up one directory.

pwd - Print working directory


 pwd: Display the current working directory.

cp - Copy files or directories


 cp file1.txt file2.txt: Copy 'file1.txt' to 'file2.txt'.
 cp -r dir1/ dir2/: Copy the 'dir1' directory and its contents to 'dir2'.
 cp -u *.txt destination/: Copy only newer files to the destination.
 cp -i file.txt backup/: Prompt before overwriting files in the backup directory.
 cp -a source/ destination/: Copy preserving ownership and timestamps.

mv - Move or rename files/directories


 mv file1.txt newfile.txt: Rename 'file1.txt' to 'newfile.txt'.
 mv dir1/ newdir/: Move 'dir1' to 'newdir'.
 mv file1.txt ~/Documents/: Move 'file1.txt' to the 'Documents' directory.
 mv *.txt backup/: Move all text files to the 'backup' directory.
 mv -u dir1/* dir2/: Move only newer files from 'dir1' to 'dir2'.

rm - Remove/delete files or directories


 rm file1.txt: Remove 'file1.txt'.
 rm -r dir1/: Remove 'dir1' and its contents recursively.
 rm -f file.txt: Forcefully remove 'file.txt'.
 rm -i *.txt: Prompt before removing each text file.
 rm -rf oldfiles/: Remove 'oldfiles' directory and its contents forcefully.

mkdir - Create a new directory


 mkdir newdir: Create a new directory named 'newdir'.
 mkdir -p dir1/dir2: Create nested directories 'dir1' and 'dir2'.
 mkdir -m 755 mydir: Create a directory with specific permissions.
 mkdir -v test: Create a directory and display a message.
 mkdir --help: Display help information for the mkdir command.

rmdir - Remove an empty directory


 rmdir emptydir: Remove the empty directory 'emptydir'.
 rmdir -p dir1/dir2: Remove nested directories 'dir1' and 'dir2'.
 rmdir --ignore-fail-on-non-empty nonemptydir/: Remove non-empty directory without error.
 rmdir --version: Display the version of the rmdir command.
 rmdir --help: Display help information for the rmdir command.

touch - Create an empty file


 touch newfile.txt: Create an empty file named 'newfile.txt'.
 touch -c existingfile.txt: Update the access and modification times of an existing file.
 touch file1.txt file2.txt: Create multiple empty files at once.
 touch -t 202201011200 file.txt: Set a specific timestamp for the file.
 touch --help: Display help information for the touch command.

cat - Display or concatenate files


 cat file1.txt: Display the contents of 'file1.txt'.
 cat file1.txt file2.txt: Concatenate the contents of 'file1.txt' and 'file2.txt'.
 cat -n file.txt: Display line numbers while viewing the file.
 cat > newfile.txt: Create a new file and write content interactively (use Ctrl+D to finish).
 cat -A file.txt: Display non-printing characters.

nano - Text editor for the terminal


 nano filename.txt: Open the 'filename.txt' file in the nano editor.
 nano +10 filename.txt: Open 'filename.txt' and position the cursor at line 10.
 nano -B filename.txt: Create a backup of 'filename.txt' before editing.
 nano --nowrap filename.txt: Disable line wrapping in nano.
 nano --help: Display help information for the nano command.

grep - Search for a pattern in files


 grep pattern file.txt: Search for 'pattern' in 'file.txt'.
 grep -r "error" /var/log: Search for 'error' recursively in '/var/log'.
 grep -i "pattern" file.txt: Perform a case-insensitive search.
 grep -n "pattern" file.txt: Display line numbers for matching lines.
 grep -o "word" file.txt: Display only the matched part of the line.

find - Search for files and directories


 find / -name filename.txt: Search for 'filename.txt' starting from the root directory.
 find . -type d -name dir*: Search for directories starting from the current directory.
 find /home/user -mtime -7: Find files modified within the last 7 days.
 find /var/log -size +1M: Find log files larger than 1 megabyte.
 find . -name "*.txt" -exec cp {} backup/ \;: Find and copy all text files to the 'backup'
directory.

chmod - Change file permissions


 chmod 755 file.txt: Change 'file.txt' permissions to read, write, and execute for the owner,
and read and execute for others.
 chmod u=rw,go=r file.txt: Set specific permissions using the symbolic notation.
 chmod +x script.sh: Add execute permission to 'script.sh'.
 chmod -R 644 directory/: Recursively set read and write permissions for the owner and read-
only for others.
 chmod --reference=referencefile.txt targetfile.txt: Copy permissions from one file to another.

chown - Change file owner and group


 chown user:group file.txt: Change the owner to 'user' and group to 'group' for 'file.txt'.
 chown -h newowner:newgroup symlink: Change ownership of a symbolic link.
 chown --from=user1:user1 --to=user2:user2 file.txt: Change ownership from one user to
another.
 chown user: group file.txt: Change only the group ownership of 'file.txt'.
 chown --reference=referencefile.txt targetfile.txt: Copy ownership from one file to another.

ps - Display information about running processes


 ps: Display a snapshot of current processes.
 ps aux: Display detailed information about all processes.
 ps -ef: Display a full format listing of all processes.
 ps -u username: Display processes for a specific user.
 ps -e --forest: Display processes in a tree-like structure.

kill - Terminate a process by process ID


 kill -9 PID: Forcefully terminate the process with the specified process ID.
 killall process_name: Terminate all processes with the specified name.
 pkill -f pattern: Terminate processes matching the specified pattern.
 kill -STOP PID: Pause a process.
 kill -CONT PID: Resume a paused process.

tar - Archive files and directories


 tar -cvf archive.tar file1 file2: Create a tar archive named 'archive.tar' containing 'file1' and
'file2'.
 tar -xvf archive.tar: Extract files from the 'archive.tar' archive.
 tar -czvf archive.tar.gz directory/: Create a compressed tar archive.
 tar -tvf archive.tar: Display the contents of a tar archive.
 tar --exclude=pattern -cvf archive.tar directory/: Create a tar archive excluding files matching
the pattern.

wget - Download files from the internet


 wget http://example.com/file.txt: Download 'file.txt' from the internet.
 wget -O newname.txt http://example.com/file.txt: Download and save with a different
name.
 wget -r -np -k http://example.com: Download a website recursively for offline viewing.
 wget --limit-rate=200k http://example.com/largefile.zip: Limit download speed.
 wget --mirror -p --convert-links -P ./localdir http://example.com: Mirror a website for offline
browsing.

df - Display disk space usage


 df -h: Display disk space usage in a human-readable format.
 df -T: Display disk space usage with filesystem type information.
 df -i: Display inode usage for each filesystem.
 df -H /path: Display disk space usage for a specific path.
 df -k --output=source,size,used,avail,pcent,mountpoint: Display specific columns in kilobytes.

history - Display command history


 history: Display the command history.
 history 10: Display the last 10 commands in history.
 !!: Repeat the last command.
 !5: Repeat the fifth command from history.
 Ctrl + R: Search and execute a command from history.

You might also like