OSY MP
OSY MP
Introduction to Linux
Linux is a powerful, open-source operating system widely used for servers, desktops, and
embedded systems. It is known for its stability, security, and flexibility, making it a popular
choice among developers and system administrators. Unlike Windows or macOS, Linux is
built around the concept of a command-line interface (CLI), where users can interact with the
system by typing commands rather than using a graphical user interface (GUI).
Structure of a command
command [options] [arguments]
1. ls
Syntax: ls [options] [directory]
Use: Lists files and directories in the specified directory. It can show hidden files
(using -a) and can provide detailed information (using -l).
Example: ls -la
(lists all files, including hidden ones, in long format)
2. cd
Syntax: cd [directory]
Use: Changes the current working directory to the specified directory. Use cd .. to go
up one directory level.
Example: cd msbte/it
(navigates to the Documents directory)
3. cp
Syntax: cp [options] source destination
Use: Copies files or directories. Use -r for recursive copying of directories.
Example: cp a.txt copied.txt
(copies file.txt to the backup directory)
4. mv
Syntax: mv [options] source destination
Use: Moves or renames files and directories. Use -i for interactive mode, which
prompts before overwriting files.
Example: mv a.txt b.txt
(renames oldname.txt to newname.txt)
5. rm
Syntax: rm [options] file
Use: Deletes files or directories. Use -r to remove directories and their contents
recursively, and -f to force deletion without prompts.
Example: rm b.txt
(recursively and forcefully deletes foldername)
6. mkdir
Syntax: mkdir [options] directory
Use: Creates a new directory. Use -p to create parent directories as needed.
Example:
mkdir ty
(creates a new folder named new_folder)
7. rmdir
Syntax: rmdir [directory]
Use: Removes an empty directory. If the directory contains files, it will not delete it.
Example: rmdir ty
(removes an empty directory named empty_folder)
8. touch
Syntax: touch filename
Use: Creates a new empty file or updates the timestamp of an existing file.
Example: touch a.txt
(creates a new file named newfile.txt)
9. cat
Syntax: cat [options] file
Use: Concatenates and displays the contents of files. It can also create new files by
redirecting output.
Example: cat a.txt
(displays the contents of file.txt)
10. grep
Syntax: grep [options] pattern [file]
Use: Searches for a specified pattern within files. It supports regular expressions and
can display line numbers with -n.
Example: grep 'hello' a.txt
(finds lines containing 'hello' in file.txt)
11. echo
Syntax: echo [options] [string]
Use: Displays a line of text or a variable value. It can be used for debugging or
displaying messages.
Example: echo "Hello, World!"
(prints "Hello, World!" to the terminal)
12. pwd
Syntax: pwd
Use: Prints the current working directory path. Useful for confirming your current
location in the filesystem.
Example: pwd
(outputs the full path of the current directory)
13. man
Syntax: man [command]
Use: Displays the manual page for a specified command, providing detailed
information about its usage and options.
Example: man ls
(shows the manual for the ls command)
14. find
Syntax: find [path] [options] [expression]
Use: Searches for files and directories in a specified path. It supports various options
like searching by name, size, and modification time.
Example: find msbte/it ".txt"
(finds all .txt files in the specified directory)
15. chmod
Syntax: chmod [options] mode file
Use: Changes the file permissions for a specified file or directory. Mode can be
specified in symbolic or octal format.
Example: chmod 755 script.sh
(sets the permissions of script.sh to read, write, and execute for the owner, and read and
execute for others)
16. chown
Syntax: chown [options] user[:group] file
Use: Changes the ownership of a file or directory. You can specify both user and
group.
Example: chown user:group file.txt (changes the owner and group of file.txt)
17. df
Syntax: df [options]
Use: Displays disk space usage for file systems. It shows total, used, and available
space.
Example: df -h
(shows disk space in a human-readable format)
18. du
Syntax: du [options] [directory]
Use: Displays the disk usage of files and directories. It summarizes the space used.
Example: du -sh a.txt
(shows the total disk usage of the user’s home directory)
19. tar
Syntax: tar [options] archive-file file
Use: Archives multiple files into a single file or extracts files from an archive.
Common options include -c (create), -x (extract), and -f (file).
Example: tar -cvf archive.tar /path/to/files
(creates an archive named archive.tar)
20. wget
Syntax: wget [options] [URL]
Use: Downloads files from the web. It supports resuming downloads and
downloading recursively.
Example: wget http://example.com/file.zip
(downloads file.zip from the specified URL)
21. curl
Syntax: curl [options] [URL]
Use: Transfers data from or to a server, supporting various protocols. It can be used to
interact with APIs.
Example: curl -O http://example.com/file.zip
(downloads file.zip from the specified URL)
22. ping
Syntax: ping [options] destination
Use: Tests connectivity to a specified host by sending ICMP echo requests. It
measures round-trip time.
Example: ping -c4 google.com
(checks connectivity to Google)
23. top
Syntax: top
Use: Displays a dynamic view of system processes, showing CPU and memory usage.
It updates in real-time.
Example: top
(opens the interactive task manager)
24. history
Syntax: history [n]
Use: Displays a list of previously executed commands. The optional n limits the
output to the last n commands.
Example: history
(shows all previous commands)
25. exit
Syntax: exit [n]
Use: Exits the current shell or terminal session. The optional n can specify an exit
status.
Example: exit 0
(exits the shell with a status code of 0)
Conclusion:
Linux is a powerful operating system, and mastering basic commands like `ls`, `cd`, `cp`,
`mv`, and `rm` enables efficient file management, system navigation, and task automation.
These commands provide a foundation for advanced Linux usage, enhancing productivity in
development, system administration, or personal computing. Proficiency in these commands
unlocks the full potential of Linux, making it a valuable skill for users in various
environments.
References
1. The Linux Command Line: A Complete Introduction
2. Linux for Beginners
3. Linux: The Complete Reference