Basic Linux Commands
1. ls - List Files and Directories:
- This command is used to list the files and directories in the current working directory.
- Example:
ls
Following are some frequently used options in Linux ls commands: Options Description ls -a list all files including hidden file starting with '.'. ls -d list directories - with ' */'. ls -l list with long format - show permissions. ls -F Append indicator (one of */=>@|) to entries. ls -lh This command will show you the file sizes in human readable format. ls -r list in reverse order. ls -i list file's inode(index) number. ls -ltr View Reverse Output Order by Date. ls -t sort by time & date. ls -n It is used to print group ID and owner ID instead of their names. ls -m A list of entries separated by commas should fill the width. ls -g This allows you to exclude the owner and group information columns. ls -q Force printing of non-graphic characters in file names as the character `?';. ls -Q Place double quotations around the entry names.
2. touch - Create Empty File:
- The
touch
command creates an empty file or updates the timestamp of an existing file. - Example:
touch sample.txt
- The
3. vi - Text Editor:
- The
vi
command is a text editor that allows you to create, edit, and manipulate text files. It operates in different modes: command mode and insert mode.- To open a file for editing:
vi filename
Example: vi
sample.txt- Switch between modes: Press
i
for insert mode, andEsc
for command mode. - Basic navigation: Arrow keys,
h
,j
,k
,l
. - Editing text:
x
(delete character),dd
(delete line),yy
(copy line),p
(paste). - Save and exit:
:w
(save),:wq
(save and exit),:q!
(exit without saving). - Search text: Press
/
, type search term, and press Enter. To find the next occurrence, pressn
. - Replace text:
:s/old/new/g
(replace all occurrences of "old" with "new"). - Undo and redo:
u
(undo),Ctrl
+r
(redo).
- To open a file for editing:
- The
4. cat - Concatenate and Display File Content:
- Displays the content of a file.
- Example:
cat sample.txt
5. mkdir - Make Directory:
- Creates a new directory.
- Example:
mkdir new_directory
6. mv - Move or Rename Files or Directories:
- Moves files or directories to a new location or renames them.
- Example:
mv file.txt new_location/
ormv old_name.txt new_name.txt
- 7. cd - Change Directory:
- Allows to change thecurrent working directory.
- Example:
cd /path/to/directory
8. cp - Copy Files or Directories:
- Copies files or directories from one location to another.
- Example:
cp file.txt /path/to/destination
9. date - output the current date and time in the default format.
- Example: Thu Dec 16 12:34:56 UTC 2023
10. rm - Remove Files or Directories:
- Deletes files or directories.
- Example:
rm smaple.txt
(remove a file), rm -r directory/
(remove a directory and its contents)
11. cd ../ - One step back in directory:
- Example:
cd ../ - Go to the the previous folder
- Example:
12. ps - Display Information about Running Processes:
- Shows information about currently running processes.
- Example:
ps aux
The
aux
options display a detailed list of all processes, including those of other users. This is one of the most commonly used options.
13. cat /proc/cpuinfo:
Displays the System CPU information.
- 14. df - Display Disk Space Usage:
- Shows information about disk space usage.
- Example:
df -h
- 15. sudo yum install package_name:
- sudo: This is a command that allows a permitted user to execute a command as the superuser (root) or another user, as specified by the security policy.
- yum: This is the package management tool used on Red Hat-based systems for installing, updating, and removing software packages.
- install: This is the action you want yum to perform, indicating that you want to install a package.
16. pwd - Print Working Directory:
- Displays the current working directory, showing the full path.
- Example:
pwd
17. chmod - Change File Permissions:
- Modifies the permissions (read, write, execute) of a file.
- Example:
chmod +x script.sh
(adds execute permission to "script.sh")
18. chown - Change File Owner:
- Changes the owner and/or group of a file.
- Example:
chown user:group file.txt
19. kill - Terminate a Process:
- Terminates a running process by sending a signal.
- Example:
kill process_id
20. man - Display Manual Pages:
- Displays the manual pages for a specific command, providing detailed information.
- Example:
man ls
Comments
Post a Comment