- Published on
Linux Commands
- Authors
- Name
- Yisak Abraham
- @YisakAbrahamK
Introduction
Linux is a an operating system that offers flexibility and control. Whether you're a system administrator or a developer, knowing your way around the Linux command line can be very beneficial. In this post, I'll cover some Linux commands that you can use to navigate the file system and more.
Definitions and Tools
Linux is a family of open-source Unix-like operating systems based on the Linux kernel. It's widely used in servers, desktops, and embedded systems.
Command Line Interface (CLI) is a text-based interface used to interact with a computer system. It allows users to execute commands by typing them directly into the terminal.
Shell is a program that interprets commands and acts as an intermediary between the user and the operating system. It's the command line interface to Linux.
Kernel is the core component of an operating system. It manages the system's resources and provides the lowest-level abstraction layer for resources.
Terminal is a program that allows you to interact with the shell. It provides a text-based interface for running commands.
zsh is a shell designed for interactive use, although it is also a scripting language. It's an extended Bourne shell.
Commands
Here are some Linux commands that you can use to navigate the file system and more.
Note that this is not an exhaustive list. Some commands options and usage may not be listed here, may not be correct and may also depend on the Linux distribution you are using.
Commands for getting help
man
The man
command is used to display the manual page for a given command.
man [options] command
--help
Commands may support the --help
option to display information about how to use the command.
command --help
whatis
The whatis
command is used to display a one-line description of a command.
whatis [options] keyword
Navigating the File System and Managing Files and Directories
pwd
The pwd
command stands for "print working directory". It displays the current working directory.
pwd [options]
ls
The ls
command lists the files and directories in a directory.
ls [options] [directory]
Options
-l
: Long listing format-a
: Include hidden files-h
: Human-readable sizes
ls -lh
cd
The cd
command is used to change directories. You can use it to navigate to a different directory.
cd [options] [directory]
mkdir
The mkdir
command is used to create a new directory.
mkdir [options] directory
Options
-p
: Create parent directories if they don't exist-v
: Print a message for each created directory
rmdir
The rmdir
command is used to remove empty directories.
rmdir [options] directory
rm
The rm
command is used to remove files and directories.
rm [options] [file]
Options
-r
: Recursively remove directories and their contents-f
: Force removal without confirmation
cp
The cp
command is used to copy files and directories.
cp [options] source destination
Options
-r
: Copy directories recursively-i
: Prompt before overwriting
cp -r sourcedir destdir
mv
The mv
command is used to move files and directories.
mv [options] source destination
- We can also rename files using
mv
mv oldfile newfile
touch
The touch
command is used to create an empty file.
touch [options] filename
Other commands
clear
The clear
command is used to clear the terminal screen.
clear [options] [terminal type]
cat
The cat
command is used to concatenate and display the content of files.
cat [options] [file]
grep
The grep
command is used to search for patterns in files.
grep [options] pattern [file]
pattern
.
: Any single character^
: Start of a line$
: End of a line*
: Zero or more occurrences[]
: Any one of the characters inside the brackets[^]
: Any character not inside the brackets
find
The find
command is used to search for files and directories in a directory hierarchy.
find [options] [path] [expression]
Options
-name
: Search for files with a specific name-type
: Search for files of a specific type (f: file, d: directory)-exec
: Execute a command on the found files
find . -name "*.txt"
chmod
The chmod
command is used to change the permissions of files and directories.
chmod [options] mode file
mode
u
: Userg
: Groupo
: Othersa
: All+
: Add permission-
: Remove permission=
: Set permission
chmod u+x file
less
and more
The less
and more
commands are used to view the contents of a file one page at a time. The less
command allows both forward and backward navigation.
less file
more file
Bonus Content
>>
and >
operators
The The >>
and >
called the output redirection operators are used to redirect output to a file. They are used to save the output of a command to a file instead of displaying it on the terminal
command >> file
command > file
>>
- Appends output to the end of a file
- Creates a new file if it doesn't exist
- Preserves the existing content of the file
>
- Redirects output to a file
- Creates a new file if it doesn't exist
- Overwrites the existing content of the file
echo "Hello, World!" > hello.txt
|
operator
The The |
operator is called a pipe. It is used to combine two or more commands together. It takes the output of one command and passes it as input to another command.
command1 | command2
Conclusion
These are some Linux commands that you can use to interact with the system. I encourage you to explore more commands and experiment with them. Happy learning! 🐧