A Linux command is a program or utility that runs on the CLI – a console that interacts with the system via texts and processes. It’s similar to the Command Prompt application in Windows. Linux commands are executed on Terminal by pressing Enter at the end of the line. You can run commands to perform various tasks, from package installation to user management and file manipulation. Here’s what a Linux command’s general syntax looks like: CommandName [option(s)] [parameter(s)] A command may contain an option or a parameter. In some cases, it can still run without them. These are the three most common parts of a command: CommandName is the rule that you want to perform. Option or flag modifies a command’s operation. To invoke it, use hyphens (–) or double hyphens (—). Parameter or argument specifies any necessary information for the command. Keep in mind that all Linux commands are case-sensitive.
=================================================================
Short for superuser do, sudo is one of the most popular basic Linux commands that lets you perform tasks that require administrative or root permissions.
When using sudo, the system will prompt users to authenticate themselves with a password. Then, the Linux system will log a timestamp as a tracker. By default, every root user can run sudo commands for 15 minutes/session.
If you try to run sudo in the command line without authenticating yourself, the system will log the activity as a security event.
Here’s the general syntax:
(command)
You can also add an option, such as:
-k or –reset-timestamp invalidates the timestamp file.
-g or –group=group runs commands as a specified group name or ID.
-h or –host=host runs commands on the host.
cd Photos.
If you want to switch to a completely new directory, for example, /home/username/Movies, you have to enter cd followed by the directory’s absolute path:cd /home/username/Movies
Here are some shortcuts to help you navigate: cd ~[username] goes to another user’s home directory. cd .. moves one directory up. cd- moves to your previous directory.ls /home/username/Documents
Here are some options you can use with the ls command: ls -R lists all the files in the subdirectories. ls -a shows hidden files in addition to the visible ones. ls -lh shows the file sizes in easily readable formats, such as MB, GB, and TB. 5. cat command Concatenate, or cat, is one of the most frequently used Linux commands. It lists, combines, and writes file content to the standard output. To run the cat command, type cat followed by the file name and its extension. For instance:cat filename.txt.
Here are other ways to use the cat command: cat > filename.txt creates a new file.cat filename1.txt filename2.txt > filename3.txt
merges filename1.txt and filename2.txt and stores the output in filename3.txt.tac filename.txt
displays content in reverse order.cp filename.txt /home/username/Documents
To copy files to a directory, enter the file names followed by the destination directory:cp filename1.txt filename2.txt filename3.txt /home/username/Documents
To copy the content of a file to a new file in the same directory, enter cp followed by the source file and the destination file:cp filename1.txt filename2.txt
To copy an entire directory, pass the -R flag before typing the source directory, followed by the destination directory:cp -R /home/username/Documents /home/username/Documents_backup
mv filename.txt /home/username/Documents.
You can also use the mv command to rename a file:mv old_filename.txt new_filename.txt
mkdir [option] directory_name
For example, you want to create a directory called Music:mkdir Music
To make a new directory called Songs inside Music, use this command:mkdir Music/Songs
The mkdir command accepts many options, such as: -p or –parents create a directory between two existing folders. For example, mkdir -p Music/2020/Songs will make the new “2020” directory. -m sets the file permissions. For instance, to create a directory with full read, write, and execute permissions for all users, enter mkdir -m777 directory_name. -v prints a message for each created directory.rmdir -p mydir/personal1
rm filename
To remove multiple files, enter the following command:rm filename1 filename2 filename3
Here are some acceptable options you can add: -i prompts system confirmation before deleting a file. -f allows the system to remove without a confirmation. -r deletes files and directories recursively.touch /home/username/Documents/Web.html
locate -i school*not
The command will search for files that contain the words school and note, whether they use uppercase or lowercase letters.find [option] [path] [expression]
For example, you want to look for a file called notes.txt within the home directory and its subfolders:find /home -name notes.txt
Here are other variations when using find:find -name filename.txt
to find files in the current directory.find ./ -type d -name directoryname to look for directories.