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
pwdPrint the current working directory.
ls
lsList the contents of a directory.
ls -l: Detailed list with file permissions.ls -a: Show hidden files.
cd
cdChange directory.
cd <directory>: Navigate to a specific directory.cd ..: Move up one level.
File Operations
touch
touchCreate an empty file.
touch <filename>: Create a file.
mkdir
mkdirCreate a new directory.
mkdir <directoryname>: Create a directory.
cp
cpCopy files or directories.
cp <source> <destination>: Copy a file or directory.
mv
mvMove or rename files or directories.
mv <source> <destination>: Move or rename a file or directory.
rm
rmRemove files or directories.
rm <filename>: Remove a file.rm -r <directoryname>: Remove a directory and its contents.
Viewing and Editing Files
cat
catView the contents of a file.
cat <filename>: Display the contents of a file.
less and more
less and moreView the contents of a file page by page.
less <filename>: Use the arrow keys to navigate.
nano or vim
nano or vimText editors for creating and editing files.
nano <filename>orvim <filename>: Open a file for editing.
File Permissions
chmod
chmodChange file permissions.
chmod <permissions> <filename>: Modify file permissions.
Searching and Finding
find
findSearch for files and directories.
find <directory> -name <filename>: Search for a specific file.
grep
grepSearch for text within files.
grep <pattern> <filename>: Search for a specific pattern in a file.
Process Management
ps
psList running processes.
top or htop
top or htopMonitor system processes in real-time.
kill
killTerminate processes.
kill <processID>: Terminate a process.
System and Network
lsof
lsofList open files and processes.
curl
curlTransfer 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
wgetDownload files from the web.
tail
tailDisplay the last few lines of a text file.
head
headDisplay the first few lines of a text file.
dig
digQuery 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
sedSED 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
awkAWK 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 usersLast updated