Basic Unix Terminal Commands
Unix-like operating systems, including Linux, provide a powerful command-line interface (CLI) for managing and interacting with your system. Here are some basic terminal commands:
Navigation
pwd
pwd
Print the current working directory.
ls
ls
List the contents of a directory.
ls -l
: Detailed list with file permissions.ls -a
: Show hidden files.
cd
cd
Change directory.
cd <directory>
: Navigate to a specific directory.cd ..
: Move up one level.
File Operations
touch
touch
Create an empty file.
touch <filename>
: Create a file.
mkdir
mkdir
Create a new directory.
mkdir <directoryname>
: Create a directory.
cp
cp
Copy files or directories.
cp <source> <destination>
: Copy a file or directory.
mv
mv
Move or rename files or directories.
mv <source> <destination>
: Move or rename a file or directory.
rm
rm
Remove files or directories.
rm <filename>
: Remove a file.rm -r <directoryname>
: Remove a directory and its contents.
Viewing and Editing Files
cat
cat
View the contents of a file.
cat <filename>
: Display the contents of a file.
less
and more
less
and more
View the contents of a file page by page.
less <filename>
: Use the arrow keys to navigate.
nano
or vim
nano
or vim
Text editors for creating and editing files.
nano <filename>
orvim <filename>
: Open a file for editing.
File Permissions
chmod
chmod
Change file permissions.
chmod <permissions> <filename>
: Modify file permissions.
Searching and Finding
find
find
Search for files and directories.
find <directory> -name <filename>
: Search for a specific file.
grep
grep
Search for text within files.
grep <pattern> <filename>
: Search for a specific pattern in a file.
Process Management
ps
ps
List running processes.
top
or htop
top
or htop
Monitor system processes in real-time.
kill
kill
Terminate processes.
kill <processID>
: Terminate a process.
System and Network
lsof
lsof
List open files and processes.
curl
curl
Transfer data with URLs.
curl https://example.com
: Make a simple GET request.curl -O https://example.com/somefile.txt
: Download a file.curl -d "key1=value1&key2=value2" -X POST https://example.com/api
: Send POST data.curl -i https://example.com
: View response headers.curl -H "User-Agent: MyUserAgent" https://example.com
: Add custom headers.
wget
wget
Download files from the web.
tail
tail
Display the last few lines of a text file.
head
head
Display the first few lines of a text file.
dig
dig
Query DNS servers for domain information.
dig example.com
: Basic domain query.dig example.com MX
: Query for specific DNS record type.dig example.com @8.8.8.8
: Query a specific DNS server.
sed
sed
SED stands for Stream Editor.
Used for text manipulation and substitutions.
Example: Replace "old" with "new" in a file:
sed 's/old/new/g' filename.txt
awk
awk
AWK is a versatile text processing tool.
Named after its creators: Aho, Weinberger, and Kernighan.
Useful for data extraction, manipulation, and reporting.
Example: Calculate the sum of the third column in a file:
awk '{sum+=$3} END {print sum}' datafile.txt
These are some of the fundamental Unix terminal commands. To get more information on any of these commands, you can use the man
command followed by the command name. For example, man ls
will display the manual page for the ls
command, explaining its usage and options in detail.
ssh -i <ssh key> <user>@<ip address>
#
su <user>
cat /etc/passwd
**-/
# See all users
Last updated