man <command name>- The main command returns a helpful help page that gives you a brief description of what exactly a command does and how to use it.
- In case that man doesn't work, make sure that you have
mandocsormaninstalled. - The manual entries can also be accessed via a browser.
- Sometimes a command is too niche to warrant a page in the manual. In such cases you can use the help flags. There is no set standard but they're usually one of the two
<command> --helpor<command> -h- If one doesn't work, try the other.
suopens the current shell as root whilesudoruns a specified command as root.- In Linux root priviliges are very similiar to Adminstrator priviliges in Windows
- Be very careful when running anything as root. It can break your system.--
- It also requires the current user to know the root password as well be a part of the sudoers list
cdis used to traverse the filesystem from the terminalcd <path>will move the terminal to the defined pathcd ..will move the terminal to the parent directory if it existscd /will move the terminal to the root directorycd ~or justcdwill move the terminal to the home directory
lsshows all the visible files and folders in directory.ls -ashows all the hidden and visible files and folders in the directory.ls -Ashows almost all the hidden and visible files and folders in the directory(It excludes the.which loops back to the current directory and the..which points to the parent directory)ls -ldisplays all the visible files and folders and lists them in tabular form with some extra information(like size, author, date modified, etc)
touch <filename>creates an empty folder with the name specified
mkdir <foldername>creates a folder with the specified name in the current location of the terminal.mkdir -p <path_to_folder>creates the folder in the path specified as well as all the missing folders in the path to the folder.
mv <source_path> <destination_path>moves a file from the source_path to the destination_pathmv <path>/old_name <path>/new_namewill rename a file namedold_namein the location<path>tonew_name
cp <source_path> <destination_path>copies a file from the source_path to the destination_pathcp -ris used to copy folders by recursively copying their contents
rm <file1> <file2> <file3>deletes the files mentioned- The Recycle Bin or Trash does not exist when it comes to deleting things from the terminal so be careful with this command.
rm -f <file>force deletes the file and overrides any warnings.rm -r <folder>recursively deletes the contents of a folder and finally deletes the folder too.- UNDER NO CIRCUMSTANCE SHOULD YOU RUN ANY OF THE FOLLOWING UNLESS YOU ARE ABSOLUTELY SURE ABOUT WHAT YOU ARE DOING
sudo rm -rf /this will delete everything in your root directoryrm -rf ~this will delete everything in your home directory
- Running
rm -rfwith elevated priviliges in a dangerous location will most probably break your OS. - Exercise caution.
grepis used to search the content of a specified file or durectory for a given string or a regexgrep '<search_term>' <file>searches for thesearch_termin the<file>grep -i '<search_term>' <file>will search for thesearch_termin a case insensitive way.grep -r '<search_term>' <folder_path>will search for thesearch_termrecursively within the specified directory.
catallows the user to execute basic text modification from the terminal- It is not a full blown editor like Vim or Emacs but it can read and append to files
cat <file>will display the contents of the filecat >> <file>will allow you to enter some text into the terminal. The entered text is then appeneded to the end of the file.
pwdreturns the path to the active directory
topdisplays the processes running in real time. It also displays resource utilization and other information regarding the process.
pkill <pattern>kills the first processes with the string<pattern>in their name
pgrep <pattern>returns the PID of all processes with the string<pattern>in their name
kill <PID>terminates the process with the PID specified
echo "Hello, World!"will print Hello, World! on the terminal.
wc <file>will print the number of words in a filewc -l <file>will print the number of lines in a file
- We can pass the output of one command to the input of another by using the
|operator. grep -r '<search_term>' <folder_name> | wc -lwill return the number of entries that match the search
sshis program used to log into and access a machine. It was designed as a more secure replacement totelnet.- The commands that you type into your
sshshell terminal are excecuted on the host instead of the login shell ssh user_name@host(IP/Domain_name)will ssh into the specified host in the useruser_name
scpis Secure Copy, it is mostly used to copy files over ssh.- Its usage is very similar to
cp, one key difference is that we need to mention the user and the hostname of the devices in the address. scp -r us<er1@host1:home/Documents/ user2@host2:home/target_pathwill copy the contents of theDocumentsfolder inuser1's home directory inhost1to the home directory ofuser2inhost2host.
fgets()is a system call in thestdio.hpackage.fgets()reads in at most one less than size characters from stream and stores them into the buffer pointed to bys. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A terminating null byte (aq\0aq) is stored after the last character in the buffer.
#include <stdio.h>
int main() //Program that uses fget() to accept a string from the user and print it
{
char buf[10];
fgets(buf, 10, stdin);
printf("%s\n", buf);
return 0;
}