Fundamental of Computing Week 9: 9 October to 15 October (Basic Commands in Linux)
Basic Commands in Linux
Introduction
- Commands are known as 'programs' as when you run a command, the accompanying program code, written for the command, is executed.
- File management in Linux becomes easy if the right commands are known.
Linux Commands
- In Linux commands:
- Blue is used to indicate directories.
- White is used to identify files.
- Similar color schemes are used in different distribution of Linux.
- Commands are case-sensitive.
- ls command is used to see the list of files on Linux or UNIX system.
- ls-R command is used to show all the files not only in directions but also subdirectories.
- ls-al command is used to give detailed information about the file in a column format.
Listing Hidden Files
- ls-a command is used to access hidden files.
- Hidden items in UNIX/Linux begin with a '.' period symbol at the beginning of the file and directory.
- Any directory or file beginning with a '.' will be ignored until explicitly requested.
Creating and Viewing Files
- The cat- command displays text files. It can also be used to duplicate, combine and create new text files.
- To create a new file, use the command:
- cat>filename
- Add content
- Press 'ctrl + d' return to command prompt
- To view a file, use the command cat.
- To specify, use the command cat filename.
- To combine two files, use the command cat file1 file2 > newfilename
Deleting Files
- The rm command removes files from the system without requiring confirmation.
- To make sure a file is removed or not we can check using the ls command after deletion.
- The mv command is used to move a file to different directory.
- The mv command requires superuser/root user privileges.
- Regular users can run programs with the security rights of the superuser/root user by using the sudo program.
Moving and Files
- To use the sudo program, the sudo command requires password authentication.
- The password given for sudo is saved for 15 minutes per termnal by default and it avoids the need to repeatedly enter the password
- Following authentication, the system will execute requested command.
- Sudo keeps a record of every command executed.
- System administrators can hunt down the person responsible for unfavorable system changes.
Re-Naming Files
- The command mv can also be used to rename a file.
- The syntax is mv filename newfilename.
Directory Manipulation
- The command mkdir is used to create directories.
- It creates a subfolder in the current working directory, which is normally the 'Home Directory'.
- mkdir mydirectory is the syntax.
- To create a directory in a place other than the 'Home directory' i.e., create a directory 'file' under '/tmp' directory, we can use the command mkdir/tmp/file.
- You can also create multiple directories at a time.
Removing Directories
- The command rmdir is used to remove a directory.
- For example, rmdir file will delete the directory named file.
- Make sure there are no files or subdirectories in the directories in the directory you wish to delete. Before deleting the parent directory, delete the files/subdirectory.
Renaming Directories
- The command mv can also be used for renaming directories.
- The syntax for the mv command is oldfilename newfilename.
Search Command
- grep (global regular expression print) is a command that searches files for text that matches a given pattern and prints it.
- The regular expression can be used to define the pattern.
- You can use the command <man grep>
- The command find is used to search files and directories.
Other Important Commands
- The command history is used to display all commands used in the past for the current terminal session.
- This command helps the user to refer to previously submitted commands and re-use them.
- The command clear is used to remove all terminal clutter and have a clean window to work in.
Text Editor
- vi (Visual Editor) or vim (Visual Editor Improved) is a terminal-based text editor that can be used to create any type of file.
- The command <vi> or <vim> to work with it.
- A text editor called nano that is built-in the vi/vmi.
- A built-in software named gedit is present if you want to use the GUI based text editor.
- The command <geidit> is used to launch it.
- The command <gedit file_name> is used to open the file in gedit.
Comments
Post a Comment