Commands to identify yourself
In Linux, there is a command to find out what account you are using and where you are currently.
whoami literally tells you who the account you are using.
pwd stands for “print working directory” and shows the current working directory.
With these two things, you can know which account you are currently working on and on which path.
Commands to control files
In Linux, everything is managed as files.
Not only text or applications, but also network sockets and directly attached hardware are managed as files.
File management methods include creating, deleting, copying, and moving, and corresponding commands exist in Linux.
Commands to create a file or directory (folder)
There are 3 ways to create them.
- Use touch command
- Use a text editor
- using the cat command (explained in another section)
touch command
Touch is basically a command to modify the date and time of a file, but it can also be used to create a file with a size of 0.
You can use it like this:
touch newfile
Use a text editor
Linux has a variety of text editors.
I will use vi among them.
Here’s how to use it:
vi newfile.filetype
Command to delete a file or directory (folder)
You can delete them using the rm command.
rm -option filename
Most used options
- f: Forcibly deletes without confirmation.
- r: Deletes all subdirectories as well.
Without the -r option, the following error appears.
rm: cannot remove 'Adobe': Is a directory
Command to copy files or directories (folders)
You can perform a copy using the cp command.
Here’s how to use it:
cp -option original_file new_file
Frequently used options
- f: Overwrite if it already exists.
- r: Copies all subdirectories as well.
Commands to move files or directories (folders)
You can use the mv command to move files.
Here’s the basic usage:
mv original_file destination_file
The directory can be used in the same way.
Frequently used options
- b: If a file with the same name exists in the same path, the existing file is backed up and moved.
- f: If a file with the same name exists in the same path, it is immediately overwritten without a query.
- i: If a file with the same name exists in the same path, it asks whether to overwrite it.
- v: Shows the progress.
Special command ‘cat’
Wikipedia defines the ‘ cat’ command as a standard Unix utility that reads files sequentially and writes them to standard output.
The cat command is also reminiscent of a cat, but is derived from ‘concatenate ‘.
The ‘ cat ‘ command creates a file using redirects. Sometimes it can be created by typing with the keyboard, sometimes it can be created by concatenating one or more files to create a new file or concatenating two or more files to create it.
Command Usages
1) Display the contents of the file in the terminal.
cat filename
2) Merge multiple files to make one file.
cat file1 file2 > file3
3) Concatenate multiple files to an existing file.
cat file1 >> file2
4) Writes the content received through the stdin stream to a file.
cat > new_file
History command
It literally shows the command history.
This is very useful when you can’t remember the command you entered.
history
Commands used when high privileges are required
Elevated privileges are sometimes required to install packages or do some specific tasks on Linux.
There are two ways to do this, the first is to log in with the root account.
A password is not set for the root account at first, so you need to set a password after installation.
You can set the password with the following command.
passwd username
After the setting is complete, when accessing the account, you can use the su command to access it.
su username
su stands for ‘substitute user’.
Also, as an alternative is the sudo command, which only runs some software with that privilege.
sudo command(or application) -options ...
This allows users to perform only special functions without accessing unnecessary privileges.
Wrap-up
The basics of Linux are handling files well.
You can be a great Linux user if you are good with files and have the necessary permissions.