Basic Bash Commands for Linux Newbies
Although bash is fast and powerful, it is also difficult for beginners. If you are just getting started with Terminal on bash or Linux, make sure you know these basic commands to avoid getting lost and breaking things.
related:
- The 6 most useful Linux commands for new users
- 17 interesting Linux commands to run in the terminal
- 5 deadly Linux commands you should never run
- Thirteen useful tools for using text on the command line
Navigation Bash
CD
First enter the following to use this command cd
Then the path to the directory. Path is the path to the file folder, showing all the folders you need to go through. Folders are separated by forward slashes (/). For paths with spaces, you can enclose the entire path in quotes, or you can add a backslash () before the space.
cd path/to/follow
All paths are explained from your current working directory. To specify a path that is not in your current working directory, you need to navigate to the parent folder of the path or use a fully qualified path. A kind Fully qualified road Is the “full address” of the file on the system, starting from the root drive (indicated by /) and ending at the destination directory or file.
cd
Use a lot of shorthand to quickly browse directories. For example, a single slash (/) indicates the “root” directory, which is the system’s boot drive. As mentioned earlier, the tilde (~) indicates the home directory of the current user. A period (.) Indicates the current folder, and two periods (..) indicate the parent folder of the current working directory. The parent folder is the folder containing the working directory.
The backslash () is particularly special. Called “escape character”, it means that any special character should be treated specially. In this case, it means that the space is part of the file path, not the space between two different commands or parameters.
ls
To view the contents of the directory, use ls
For “list”. This command lists all files and directories in the current directory. Its most useful features are accessed through “flags”, which are short additional commands attached to the main command to change options or expand functionality. They are preceded by a dash or two (-), usually a letter.
ls
There are many other very useful signs ls
. Favorites include the following:
-a
Show hidden and dot files (files that start with.)-h
Display file size in human-readable units-S
Sort by file size, from big to big (note the capital S)-t
Sort by modification time, newest first
If you want to use multiple flags, just string them together. For example, if you want to see hidden files in a long format folder with a human-readable file size, you can run ls -lah
.
password
The command takes no parameters, so press Enter immediately after running. of pwd
The command shows the standard path pResentment wEugene dIrritability, so it is initialism.
pwd
All commands you execute are automatically executed in the current working directory. E.g, mkdir
The command will create a directory in your current working directory. Otherwise, you need to use Fully qualified road, Beginning with / to indicate the system root directory.
man
man command
Opens the man page or man page for the specified command. E.g, man chmod
The man page for the “chmod” command will be displayed in your terminal window. These entries show usage information, signs and examples. If you want to learn more about the function or available options of a command, be sure to read the manual page for the command first.
Cat
cat file
Universal reader for any file type. Run it on a text file to display the contents of the file in the console. cat
The contents of almost all files are displayed, but the output may not always be human-readable or meaningful to you. Therefore, Unix professionals rarely use it, but beginners will find it helpful to stumble upon the file system.
Working with files and directories
cp
Create a copy of the file “filename.doc” in “path / to / directory / newfilename.doc”. You can think of it as a copy and paste operation. If the file name already exists, the copy operation will not complete.
cp filename.doc path/to/directory/newfilename.doc
MV
Move “foo.txt” to “bar.txt”. You can think of this command as a cut and paste operation. We also use mv
Used to rename files because we are actually “moving” them to the new name. Please note mv
After the write operation is complete, the command deletes the original version of the file.
mv foo.txt /path/to/bar.txt
R M
Delete the contents of the directory and all the files it contains. of -r
Logo manufacturing rm
, Or delete, recursively, and -f
Marking closes all confirmation dialogs. This command is more powerful, sudo rm -rf
Be extra careful. It clears the boot drive without warning or complaints, so handle it with care.
rm -rf contents/
touch
If a file with the specified name already exists, the modification time will be changed to the current time. If the file does not exist, an empty file with the same name will be created immediately.
touch file
McDeere
Creates a directory with the specified name in the working directory. To create a parent directory as needed, use -p
flag. As long as there are no other errors, this will create all the necessary parent directories to execute your command, allowing you to create a multi-level directory hierarchy in one line.
mkdir directory
rmdir
Delete the directory under the specified path.
rmdir directory
Command modifier
Modifiers adjust existing commands so that they do or do something different than normal.
sudo command
sudo
On behalf of the “super user”, it does nothing by itself. Instead, it empowers the next command. When you type sudo
Before executing the command, you can temporarily elevate yourself to get permission from the root user, allowing you to perform actions that you would normally not perform.
However, with the development of superuser capabilities, superusers will take responsibility. It also enables you to break things up so badly, so be careful when studying. Make sure you fully understand the parts of the command you are executing, especially when you find the command online.
After use sudo
, You need to enter the administrator password. When you do this, the input cursor will not move, but keystrokes will be captured. Just press Enter when done to execute the command.
sudo !!
Run the last command again, but this time with administrator rights. So-called “Bang” command (!!) is a shortcut to repeat the previous command.
>
The caret is called “redirection” and sends the text-based output of the command to a file. E.g, ls > filelist.txt
Will send output ls
Go to “filelist.txt”. If the target file does not exist, it is created.
|
Called a “pipe”, this symbol is similar to a redirect, but is used only for commands. It sends the output of one command to the input of another command.
Modify permissions
Permissions affect which users can view, edit, and execute specific files. Files and folders have an owner (usually the user who created the file) and a mode that controls who can access the file and how it is handled.
These commands are the first commands we will use sudo
use. please remember sudo
Promoting us to superusers gives us the power of a temporary administrator. This is almost always necessary when dealing with file permissions, because not every file will be owned by the current user.
chmod
Stands for “Change Mode” and adjusts permissions for files and folders. Like chown
, It can be run on a single file or you can use -R
flag.
sudo chmod 775 file
File permissions can be expressed in several ways, but the “number mode” (775) used above is the most common.
sudo chown -R sarah foo/bar
Change the owner of each file in the given directory to the user “sarah”. -R
flag makes the command recursive, but it can also be run without the flag on a single file. Use a period (.) Instead of foo / bar to run this command in your current working directory.
in conclusion
To learn these commands quickly, you can use bash and Terminal even if you don’t need them. Rather than using drag and drop to move directories, try using mv
command. The more commands you actually use, the faster your skills will improve.
Image Source: Autopilot
Ranch
Ranch
Ranch
Ranch