Linux is a versatile and powerful operating system, and it provides a wide range of commands for managing and interacting with the system. Here are some commonly used Linux commands that can be helpful for various tasks:
File and Directory Operations:
ls
: List files and directories in the current directory.pwd
: Print the current working directory.cd <directory>
: Change the current directory.mkdir <directory>
: Create a new directory.touch <file>
: Create an empty file.cp <source> <destination>
: Copy files or directories.mv <source> <destination>
: Move or rename files or directories.rm <file>
: Remove files.rmdir <directory>
: Remove empty directories.chmod <permissions> <file>
: Change file permissions.chown <user>:<group> <file>
: Change file ownership.File Viewing and Editing:
cat <file>
: Display the contents of a file.more <file>
or less <file>
: View file contents page by page.nano <file>
or vim <file>
: Open a text editor to edit a file.Searching for Files and Text:
find <directory> -name <filename>
: Search for files by name.grep <pattern> <file>
: Search for text patterns in files.locate <filename>
: Quickly find files by name (requires an updated database).Process Management:
ps
: List running processes.top
or htop
: Monitor system processes and resource usage.kill <PID>
: Terminate a process by its Process ID.killall <process-name>
: Terminate all processes with a given name.System Information:
uname -a
: Display system information, including the kernel version.df -h
: Show disk space usage.free -h
: Display memory usage.lscpu
or nproc
: Get CPU information.lsblk
: List block devices and their information.Package Management:
apt-get
or apt
(Debian/Ubuntu):
sudo apt-get update
: Update package lists.sudo apt-get install <package>
: Install a package.sudo apt-get remove <package>
: Remove a package.yum
(Red Hat/CentOS):
sudo yum update
: Update packages.sudo yum install <package>
: Install a package.sudo yum remove <package>
: Remove a package.User and Permissions:
whoami
: Display the current user.passwd
: Change the user password.useradd
and userdel
: Create and delete users.usermod
: Modify user attributes.sudo
: Execute commands with superuser privileges.su <username>
: Switch to another user.Networking:
ifconfig
or ip addr
: Display network interface information.ping <host>
: Send ICMP echo requests to test network connectivity.netstat
or ss
: Display network statistics and connections.ssh <user>@<host>
: Connect to a remote host using SSH.scp <file> <user>@<host>:<destination>
: Securely copy files between hosts.Compression and Archiving:
tar
: Archive files and directories.gzip
or gunzip
: Compress and decompress files.zip
and unzip
: Create and extract ZIP archives.System Logs:
dmesg
: Display kernel messages.journalctl
: View system logs using systemd's journal.These are just a few of the many Linux commands available. Linux offers a rich set of tools and commands for system administration, development, and day-to-day tasks, so it's worth exploring the man pages and documentation for specific commands to learn more about their options and capabilities.
Here are some useful Linux commands:
General purpose commands:
File and directory management commands:
Networking commands:
System administration commands:
These are just a few of the many useful Linux commands. For more information, please see the Linux man pages or the Linux documentation.
Here are some examples of how to use Linux commands:
ls
my-dir
:
mkdir my-dir
my-dir
:
cd my-dir
myfile.txt
to the my-dir
directory:
cp myfile.txt my-dir
my-dir
directory:
rmdir my-dir
.txt
extension:
find . -name "*.txt"
grep -r "hello" .
ping google.com
192.168.1.100
using SSH:
ssh user@192.168.1.100
top
1234
:
kill 1234
Linux is a powerful operating system with a wide range of commands available. By learning the basic Linux commands, you can start to use Linux to manage your files, system, and network more effectively.