6.5 KiB
6.5 KiB
title
| title |
|---|
| Basic Linux Commands |
Basic Linux Commands
When starting out with linux, there are some basic commands everyone should know.
- cd - change directory
- cd followed by a directory or file path will take you inside that directory(folder).
- ls - list command
- Type
lsand the contents of the current directory will be displayed. - Two common flags used with
lsare-land-a, they can be used together and chained as such:ls -la. The-lflag will show you files in list order and in long format including a display of permissions,-awill show dot type files which are typically hidden in a GUI file finder such as.envfiles - Flag ordering does not matter, so the previous command could be written as
ls -al
- man - manual command
- Shows you the manual for the following command. This is very helpful when trying to figure out how an unfamiliar command works. For example, type
man lsfor everything you need to know about the ls command. Typeqto exit.
- pwd - path
- Type
pwdto display the path to your current directory.
- mkdir - make directory
- This command, followed by the name you wish to name your directory, creates a new directory.
mkdir folder1will make a new directory called folder1.
- rmdir - remove directory
- Removes the directory that follows the command.
rmdir folder1will delete the directory named folder1 if it exists.
- rm - remove
- This command removes files, not directories.
rm file.txtwill remove the file named file.txt as long as it exists and is in the current directory. - Warning, this command is capable of destroying entire systems, use with caution
- touch - creates file
- The
touchcommand is used to create a file. It can be anything, from an empty txt file to an empty zip file. 'touch new.txt' will create a new file with name new.
- mv - move
- Use the
mvcommand to move files through the command line. We can also use the mv command to rename a file. For example, if we want to rename the file “text” to “new”, we can use 'mv text new'. - Warning, this command is capable of destroying entire systems, use with caution
- right-click - copy and paste
- This one is less of a command and more of a how-to, however, it is very useful for doing almost anything in a terminal on linux. To begin, highlight text like normal and then "right-click" on your mouse to copy a selection. You should see the highlighted portion become un-highlighted, this means you copied the selection. Now "right-click" on where you want to paste the selection and you're done.
- less - view file content
- Use
less filename.txtto view contents of a file and navigate through them. By default, less will go through the file page by page.
- cat - display file's textual contents
- Use this command to display text from within a given file on your terminal. Entering
cat myFile.txtin your terminal will display the contents of the filemyFile.txton screen. Thecatcommand can be a very handy tool when used with the terminal pipes.
- clear - clear terminal
- Use
clearto simply clear all output from your terminal.
- cp - copy files and directories
- Use 'cp' to copy a file or a direcotry with files inside it to another location using command 'cp CURRENT_FILE-LOCATION DESTINATION_FOLDER'. Add '-r' flag to copy a directory that is not empty.
- du - estimate file space usage
- Use 'du' to estimate file space usage. du is abbreviation of "disk usage". This command tool reports usage by given directory
- ln - link LINKNAME to TARGET file/directory
- Link is pointer which connects file name to actual bytes of data on the disk. More than one link can point on the same data.
- Use
lnto create a link to targeted file with linkname. Link to target is created in current working directory. By default ln creates hard link and requires existance of TARGET file/directory. If we add-s(--symbolic) to the command, symbolic link will be created.
- top - shows the system load
- Use
topto get information about running processes of your system, the amount or RAM they allocate and the CPU percentage that they use. 'Top' is interactive so do not forget to pressqwhen you want to quit.
- df -h Checks disk space in human readable form
- Shows the size, amount used, amount available and capacity percentage of mounted drives/partitions.
- grep - The grep searches any given input files, selecting lines that match one or more patterns.
- use
grepto find a file, a directory, some text in the file/directory.
- sudo - execute a command as super user
- A widely used command in the Linux command line, sudo stands for "SuperUser Do". So, if you want any command to be done with administrative or root privileges, you can use the sudo command.
- kill - stops runing process
- The
killcommand sends a signal to a running process. This default action normally stops processes. If you want to stop a process, specify the process ID (PID) in theProcessIDvariable. The shell reports the PID of each process that is running in the background (unless you start more than one process in a pipeline, in which case the shell reports the number of the last process). You can also use thepscommand to find the process ID number of commands.
- find - search for files in a directory hierarchy
findsearches the directory tree rooted at each given file name by evaluating the given expression from left to right, according to the rules of precedence, until the outcome is known (the left hand side is false for and operations, true for or), at which pointfindmoves on to the next file name.
- man - Show the manual for a command
- Use
manto see manual of any commmand. It will show different ways a given command can be used
Example:man ls
- ps - Show active processes
- Use
psto see running processes, and their process IDs
Example:ps
- history
- Use
historyto see previously entered commands
Example:history
Useful Resources for Practice:
- JSLinux: Run the terminal inside your browser. Great for practice.
- LearnShell: Interactive Linux shell (terminal) tutorials.
- LinuxJourney: A collection of beginner-friendly terminal tutorials.