linux_cmd[1]
linux_cmd[1]
File and directory operations are fundamental in working with the Linux operating system. Here are some
commonly used File and Directory Operations commands:
• rm -f file.txt
forcefully deletes the file
“file.txt” without confirmation.
• cp file.txt destination
copies the file “file.txt” to the
specified destination.
mv Move/rename files • mv file.txt new_name.txt
and directories. renames the file “file.txt” to
“new_name.txt”.
• mv file.txt directory
moves the file “file.txt” to the
specified directory.
head Display the first few • -n: Specify the • head file.txt
lines of a file. number of lines to shows the first 10 lines of the
display. file “file.txt”.
• head -n 5 file.txt
displays the first 5 lines of the
file “file.txt”.
tail Display the last few • -n: Specify the • tail file.txt
lines of a file. number of lines to shows the last 10 lines of the
display. file “file.txt”.
• tail -n 5 file.txt
displays the last 5 lines of the
file “file.txt”.
find Search for files and • -name: Search by • find /path/to/search -name
directories. filename. “*.txt”
searches for all files with the
• -type: Search by
extension “.txt” in the specified
file type.
directory.
2. File Permission Commands
File permissions on Linux and Unix systems control access to files and directories. There are three basic
permissions: read, write, and execute. Each permission can be granted or denied to three different
categories of users: the owner of the file, the members of the file’s group, and everyone else.
• o: Other
permissions.
• +: Add
permissions.
• –: Remove
permissions.
• =: Set
permissions
explicitly.
tar Create or extract • -c: Create a new • tar -czvf archive.tar.gz files/
archive files. archive. creates a compressed tar archive
named “archive.tar.gz” containing
• -x: Extract files
the files in the “files/” directory.
from an archive.
In Linux, process management commands allow you to monitor and control running processes on the
system. Here are some commonly used process management commands:
grep used to search for specific • -i: Ignore case • grep -i “hello” file.txt
patterns or regular distinctions while
• grep -v “error” file.txt
expressions in text files or searching.
streams and display • grep -r “pattern”
• -v: Invert the
matching lines. directory/
match, displaying
non-matching lines. • grep -l “keyword”
file.txt
• -r or -R: Recursively
search directories • grep -n “pattern” file.txt
for matching In these examples we
patterns. are extracting our
desirec output from
• -l: Print only the
filename (file.txt)
names of files
containing matches.
• -n: Display line
numbers alongside
matching lines.
In Linux, there are several commands available to gather system information. Here are some commonly
used system information commands:
In Linux, there are several networking commands available to manage and troubleshoot network
connections. Here are some commonly used networking commands:
In Linux, IO (Input/Output) redirection commands are used to redirect the standard input, output, and
error streams of commands and processes. Here are some commonly used IO redirection commands:
Command Description
cmd1 <(cmd2) Output of cmd2 is used as the input file for cmd1.
cmd > /dev/null Discards the stdout of cmd by sending it to the null device.
In Linux, environment variables are used to store configuration settings, system information, and other
variables that can be accessed by processes and shell scripts. Here are some commonly used environment
variable commands:
Command Description
env VAR1=value COMMAND Sets the value of an environment variable for a specific command.
In Linux, user management commands allow you to create, modify, and manage user accounts on the
system. Here are some commonly used user management commands:
Command Description
sudo adduser username Create a new user account on the system with the specified username.
finger Display information about all the users currently logged into the system,
including their usernames, login time, and terminal.
sudo deluser USER Remove the specified user from the specified group.
GROUPNAME
finger username Provide information about the specified user, including their username,
real name, terminal, idle time, and login time.
sudo userdel -r username Delete the specified user account from the system, including their home
directory and associated files. The -r option ensures the removal of the
user’s files.
sudo passwd -l username Lock the password of the specified user account, preventing the user from
logging in.
sudo usermod -a -G Add an existing user to the specified group. The user is added to the
GROUPNAME USERNAME group without removing them from their current groups.
10. Shortcuts Commands
There are many shortcuts commands in Linux that can help you be more productive. Here are a few of the
most common ones:
Ctrl + A Move to the Ctrl + Cut/delete from the cursor Ctrl + R Search command
beginning of the U position to the beginning of history (reverse
line. the line. search).
Ctrl + E Move to the end Ctrl + K Cut/delete from the cursor Ctrl + Escape from history
of the line. position to the end of the G search mode.
line.
Ctrl + B Move back one Ctrl + Cut/delete the word before Ctrl + P Go to the previous
character. W the cursor. command in history.
Ctrl + F Move forward one Ctrl + Y Paste the last cut text. Ctrl + Go to the next
character. N command in history.
Alt + B Move back one Ctrl + L Clear the screen. Ctrl + C Terminate the
word current command.
Ctrl + O Save the Ctrl + Y Scroll up Ctrl + Cut/delete Ctrl + W Search for a
file. one page. K from the string in the
cursor position text.
to the end of
the line.
Ctrl + X Exit Nano Ctrl + V Scroll down Ctrl + Uncut/restore Alt + W Search and
(prompt to one page. U the last cut replace a
save if text. string in the
modified). text.
Ctrl + R Read a file Alt + \ Go to a Ctrl + Mark a block Alt + R Repeat the
into the specific line 6 of text for last search.
current number. copying or
buffer. cutting.
Command Description
cw Change the current word. Deletes from the cursor position to the end of the current word
and switches to insert mode.
R Enter replace mode. Overwrites characters starting from the cursor position until you press
the Escape key.
o Insert a new line below the current line and switch to insert mode.
s Substitute the character under the cursor and switch to insert mode.
dw Delete from the cursor position to the beginning of the next word.
4dw Delete the next four words from the cursor position.
r Replace the character under the cursor with a new character entered from the keyboard.
3dd Delete the current line and the two lines below it.
ESC Exit from insert or command-line mode and return to command mode.
U Restore the current line to its original state before any changes were made.
C Delete from the cursor position to the end of the line and switch to insert mode.
10.4: Vim Shortcuts Commands:
yy Copy the current line. :wq Save and quit Vim. p Paste the copied
or deleted text.
or
:x:x
or
:set number