main linux commands
- User
main linux commands
- Assistant
main linux commands
Certainly! Here is a comprehensive list of some of the main Linux commands that are essential for navigating the Linux file system, managing files and directories, monitoring system performance, networking, and more. Each command includes a brief explanation and example usage to help you get started.
ls: List directory contents.
ls [options] [directory]ls -l /home/user-l provide a long listing format with detailed information.cd: Change the current directory.
cd [directory]cd /var/logpwd: Print working directory.
pwdpwdmkdir: Make directory.
mkdir [options] directory_namemkdir new_folderrmdir: Remove empty directories.
rmdir [options] directory_namermdir old_folderrm: Remove files or directories.
rm [options] file_or_directoryrm file.txtrm -r folder_to_deletecp: Copy files and directories.
cp [options] source destinationcp file1.txt /backup/file1.txtmv: Move or rename files and directories.
mv [options] source destinationmv file.txt /destination/mv oldname.txt newname.txttouch: Create an empty file or update file timestamps.
touch filenametouch newfile.txtcat: Concatenate and display file content.
cat [options] filenamecat README.mdmore and less: View file content with pagination.
more filenameless filenamemore largefile.txtless largefile.txtmore) or with more control (less).head and tail: View the beginning or end of files.
head [options] filenametail [options] filenamehead -n 20 logfile.txt (Displays the first 20 lines)tail -n 50 logfile.txt (Displays the last 50 lines)head outputs the first part, and tail outputs the last part of files.nano, vi, and emacs: Text editors for file editing.
nano filename, vi filename, or emacs filenamenano config.txtvi script.shnano is user-friendly for beginners, while vi and emacs are powerful editors with more features.chmod: Change file mode (permissions).
chmod [options] permissions filenamechmod 755 script.shchown: Change file owner and group.
chown [options] owner[:group] filenamechown user:group /dataps: Report a snapshot of current processes.
ps [options]ps auxtop: Display Linux tasks in real-time.
topkill: Send signals to processes.
kill [options] PIDkill 1234killall: Kill processes by name.
killall [process_name]killall firefoxdf: Report file system disk space usage.
df [options]df -h-h.du: Estimate file space usage.
du [options] [path]du -sh /var/logfree: Display amount of free and used memory.
free [options]free -huname: Print system information.
uname [options]uname -auptime: Tell how long the system has been running.
uptimeifconfig or ip: Configure network interfaces.
ifconfig [interface]ip addr show [interface]ifconfig eth0ip addr show enp0s3ping: Send ICMP ECHO_REQUEST to network hosts.
ping [options] destinationping www.google.comnetstat or ss: Network statistics.
netstat [options]ss [options]netstat -tuln, ss -tulnssh: OpenSSH SSH client (remote login program).
ssh [options] user@hostnamessh user@192.168.1.10scp: Secure copy (remote file copy program).
scp [options] source destinationscp file.txt user@remote_host:/path/grep: Print lines matching a pattern.
grep [options] pattern [file]grep 'error' /var/log/syslogfind: Search for files in a directory hierarchy.
find [path] [options] [expression]find / -name "myfile.txt"locate: Find files by name.
locate [options] patternlocate index.htmlawk: Pattern scanning and processing language.
awk 'pattern {action}' fileawk '{print $1}' data.txtsed: Stream editor for filtering and transforming text.
sed [options] 'script' filesed 's/old/new/g' file.txttar: Tape archive utility.
tar [options] archive_name.tar [files]tar -cvf archive.tar /path/to/directorytar -xvf archive.tartar -czvf archive.tar.gz /path/to/directorygzip and gunzip: Compress or expand files.
gzip filenamegunzip filename.gzzip and unzip: Package and compress (archive) files.
zip archive.zip file1 file2unzip archive.zipuseradd and adduser: Create a new user.
useradd [options] usernameadduser username (Debian/Ubuntu)sudo adduser newuserpasswd: Update a user's password.
passwd [options] [username]passwd newusersu: Switch user or become superuser.
su [options] [username]su - rootsudo: Execute a command as another user.
sudo [command]sudo apt updatewho and w: Show who is logged on.
whowNote: Package management commands vary depending on the Linux distribution.
For Debian/Ubuntu (APT-based systems):
apt or apt-get: Advanced Package Tool, a package manager.
sudo apt updatesudo apt upgradesudo apt install package_namesudo apt remove package_nameapt search package_nameFor Red Hat/CentOS/Fedora (YUM/DNF-based systems):
yum or dnf: Package manager for RPM-based systems.
sudo yum install package_namesudo yum updatesudo yum remove package_nameecho: Display a line of text.
echo [options] [string]echo "Hello, World!"date: Display or set the system date and time.
date [options]date "+%Y-%m-%d %H:%M:%S"history: Show the command history list.
historyalias: Create an alias for a command.
alias name='command'alias ll='ls -la'man: Display the manual page for a command.
man [command]man lsclear: Clear the terminal screen.
clear[command] --help: Displays a brief help message about using the command.
ls --helpman [command]: Opens the manual page for the command.
man grepinfo [command]: Provides a more detailed info page.
info bashNote: Always be cautious when using commands that can alter or remove files and directories, such as rm, mv, and chmod. Use options like -i (interactive) when available, which prompts before making changes.
Tips for Learning Linux Commands:
command [options] [arguments] format.man command to read more about each command and discover additional options.Feel free to ask if you need more detailed explanations or assistance with specific commands or tasks!