Welcome to the world of Unix, a powerful operating system used in millions of computers worldwide. Unix, known for its robustness and versatility, is the backbone of many servers, workstations, and mobile devices. As a beginner, navigating through the Unix environment can seem daunting, but mastering the basic commands is your first step towards fluency. This guide is designed to introduce you to essential Unix commands, covering everything from file operations to system status checks and network management. With clear explanations and practical examples, you’ll gain the confidence to explore and operate within the Unix or Linux system efficiently. Whether you’re a system administrator, developer, or just a curious learner, these fundamental commands will lay the foundation for your Unix proficiency.
Getting Help in Unix
man <command>
: View manual pages for commands.- Example:
man ls
- Example:
man grep
- Example:
Unix Shell Commands
clear
: Clears the terminal screen.history
: Shows the command history.- Example:
history | grep ls
- Example:
Time and Date Commands
date
: Shows the current date and time.sleep <seconds>
: Waits for a specified number of seconds.- Example:
sleep 10
- Example:
uptime
: Shows system uptime.- Example:
uptime -p
- Example:
Unix Users Commands
whoami
: Displays the current user’s username.id
: Shows user and group information.- Example:
id -u
- Example:
groups
: Lists user’s groups.passwd
: Changes the user’s password.who
: Shows who is logged in.- Example:
who -a
- Example:
last
: Shows the login history.- Example:
last -n 10
- Example:
Unix File Operations
ls
: Lists directory contents.- Example:
ls -l
- Example:
ls -a
- Example:
cp
: Copies files and directories.- Example:
cp file.txt backup.txt
- Example:
cp -r folder/ new_folder/
- Example:
rm
: Removes files or directories.- Example:
rm file.txt
- Example:
rm -rf folder/
- Example:
mv
: Moves or renames files or directories.- Example:
mv file.txt newfile.txt
- Example:
mv folder/ new_location/
- Example:
chmod
: Changes file access permissions.- Example:
chmod 755 script.sh
- Example:
chmod u+x script.sh
- Example:
chown
: Changes file or directory ownership.- Example:
chown user file.txt
- Example:
chown user:group file.txt
- Example:
Text File Operations in Unix
cat
: Shows file contents.- Example:
cat file.txt
- Example:
more
: Paginates text file viewing.- Example:
more file.txt
- Example:
less
: An improved file viewer.- Example:
less /var/log/syslog
- Example:
head
: Shows the first lines of a file.- Example:
head -n 5 file.txt
- Example:
tail
: Shows the last lines of a file.- Example:
tail -n 5 file.txt
- Example:
grep
: Searches for patterns in files.- Example:
grep "pattern" file.txt
- Example:
grep -i "pattern" file.txt
- Example:
Unix Directory Management Commands
cd
: Changes the current directory.- Example:
cd /var/log
- Example:
pwd
: Shows the current directory.ln
: Creates links to files or directories.- Example:
ln -s /path/to/file link_name
- Example:
mkdir
: Creates new directories.- Example:
mkdir new_folder
- Example:
rmdir
: Removes directories.- Example:
rmdir empty_folder
- Example:
Unix System Status Commands
hostname
: Shows or sets the system hostname.w
: Displays system load and user activity.uname
: Shows system information.- Example:
uname -a
- Example:
Reboot Commands
shutdown
: Gracefully shuts down the system.- Example:
shutdown -h now
- Example:
halt
: Abruptly stops the system.reboot
: Reboots the system immediately.
Networking Commands in Unix
ifconfig
: Manages network interfaces.- Example:
ifconfig eth0
- Example:
ip
: Newer tool for network configuration.- Example:
ip addr show
- Example:
ping
: Checks network connectivity.- Example:
ping google.com
- Example:
netstat
: Displays network statistics.- Example:
netstat -tuln
- Example:
Process Management
ps
: Lists running processes.- Example:
ps aux
- Example:
top
: Shows real-time system status.kill
: Terminates processes.- Example:
kill 1234
- Example:
kill -9 1234
- Example:
Remote Access Commands
telnet
: Insecure remote access protocol.- Example:
telnet host.example.com
- Example:
ssh
: Secure shell for remote access.- Example:
ssh [email protected]
- Example:
File Transfers Commands
ftp
: File transfer protocol client.- Example:
ftp host.example.com
- Example:
sftp
: Secure version of FTP.- Example:
sftp [email protected]
- Example:
scp
: Secure file copy.- Example:
scp file.txt [email protected]:~/
- Example:
wget
: Downloads files from the web.- Example:
wget http://example.com/file.txt
- Example: