Basic Linux Commands
Table of contents
Introduction to Linux
Linux is an open-source operating system kernel.It is suitable for diverse environments.
It has a powerful command-line interface (CLI) alongside user-friendly graphical interfaces.
Multiuser and Multitasking: It supports multiple users and tasks running concurrently. This makes it suitable for servers, where many users might need access, and for desktops, which require multitasking capabilities.
Security: Linux's open-source nature facilitates security audits and timely updates.
Variety of Distributions: Some popular ones include Ubuntu, Fedora, Debian, CentOS, and Arch Linux.
Package Management: Linux distributions use package management systems (e.g., APT, YUM, and Pacman) to facilitate the installation, removal, and updating of software.
Linux is a popular choice for servers, embedded systems, and personal computers.
Linux has GPL :General Public License
It focuses on shell scripting,networking, terminal,programming.
It is secure.
Updates are less than window
Some linux basic commands
File and Directory Management
**ls (list) :**List all contents (files and directories) in the current directory.
ls-h:
Human-readable file sizes.ls -a
: List all files and directories, including hidden ones.ls -l
: List files and directories in detailed format.ls -t
: List files and directories sorted by modification time.ls -rt
: List files and directories in reverse order of their names
pwd (print working directory) : Print the name of the directory that the user is currently working in.
**cd(change directory):**allows the user to change to a specified directory.
mkdir(make directory): allows the user to create a new directory..
Usage: mkdir directory_name
Along with mkdir we can use the "-p" flag which will create sub-directories (directories within a directory) if it does not exist.
**touch :**Create an empty file.
- Usage: touch file_name
cp :Copy files or directories.
Usage: cp source_file destination_directory
cp -r: Copy directories recursively.
**mv :**Move or rename files or directories.
- Usage:mv source_file destination
rm (remove): Remove files or directories.
Usage: rm file_name
rm -r: Remove directories recursively.
With this command, we can use the "-r" flag, which removes the files recursively within a directory but do not use "-rf" which will forcefully delete the files and will not give a prompt when deleting important files.
File viewing and Editing
cat(concatenate): Display the contents of a file.
- Usage: cat file_name
more and less Display file contents one screen at a time.
- Usage: more file_name & less file_name
head and tail Display the beginning or end of a file.
- Usage: head file_name & tail file_name
grep Search for text in files using patterns.
- Usage: grep "pattern" file_name
File permission and ownership
**chmod :**Change file permissions.
Usage: chmod permissions file_name
ls -l : to see permission of file or dir
chown command : change ownership
Process Management
ps : List running processes.
kill: Terminate processes.
- Usage: kill PID
top: Display active processes in real-time
Other commands
man :Access the manual pages for commands.
- Usage: man command_name
df: Display disk space usage
du: Display file and directory space usage
tar: Archive and compress files.
Usage: tar options archive_name files/directories
-c: Create a new archive.
-z: Compress the archive using gzip.
wget : Download files from the internet.
- Usage: wget URL
whoami::displays the username of the current user when this command is entered.