Linux is a powerful and widely used operating system with a command-line interface that allows users to interact with the system using text commands. Here are some basic Linux commands and their usage:
Linux commands and usage:
- pwd – Print Working Directory: Shows the current directory you are in.
Usage:pwd
- ls – List Files and Directories: Lists the files and directories in the current directory.
Usage:ls
(list current directory contents)
Usage:ls <directory>
(list contents of a specific directory)
Additional options:ls -l
: List with detailed information (permissions, size, owner, etc.)ls -a
: List including hidden files (files starting with a dot)
- cd – Change Directory: Change the current directory to another directory.
Usage:cd <directory>
(move to a specific directory)
Usage:cd ..
(move to the parent directory)
Usage:cd
orcd ~
(move to the home directory) - mkdir – Make Directory: Create a new directory.
Usage:mkdir <directory_name>
- rmdir – Remove Directory: Remove an empty directory.
Usage:rmdir <directory_name>
- rm – Remove Files or Directories: Remove files or directories.
Usage:rm <file_name>
(remove a file)
Usage:rm -r <directory_name>
(remove a directory and its contents)
Caution: Be careful when usingrm -r
as it permanently deletes files and directories without confirmation. - touch – Create Empty File: Create an empty file or update the access and modification times of an existing file.
Usage:touch <file_name>
- cp – Copy Files and Directories: Copy files or directories.
Usage:cp <source_file> <destination_file>
(copy a file)
Usage:cp -r <source_directory> <destination_directory>
(copy a directory) - mv – Move or Rename Files and Directories: Move files or directories from one location to another or rename them.
Usage:mv <source> <destination>
(move or rename a file or directory) - cat – Concatenate and Display File Content: Display the content of a file.
Usage:cat <file_name>
- more and less – Display File Content Page by Page: Display the content of a file one screen/page at a time.
Usage:more <file_name>
(use spacebar to go to the next page)
Usage:less <file_name>
(use arrow keys to navigate) - head and tail – Display the Beginning or End of a File:
Show the first few lines (head) or last few lines (tail) of a file.
Usage:head <file_name>
(show the first 10 lines by default)
Usage:tail <file_name>
(show the last 10 lines by default) - grep – Search for Patterns in Files: Search for a specific pattern in a file.
Usage:grep <pattern> <file_name>
- chmod – Change File Permissions: Change the permissions of a file or directory.
Usage:chmod <permissions> <file_name>
(e.g.,chmod 755 myfile
) - chown – Change File Owner and Group: Change the owner and/or group of a file or directory.
Usage:chown <new_owner>:<new_group> <file_name>
- ps – Process Status: Display information about running processes.
Usage:ps
(shows processes of the current user)
Usage:ps -ef
(shows all processes) - kill – Terminate a Process: Terminate or send a signal to a process.
Usage:kill <process_id>
(terminate a process by its ID) - man – Manual Pages: Get information about commands and their usage.
Usage:man <command>
(e.g.,man ls
)
These are just a few of the basic Linux commands. Linux provides a rich set of commands and utilities that can be combined to perform various tasks efficiently. To explore more commands and their options, you can use the man
command to access the manual pages and learn about their usage and options.