Basic Linux Commands( Comptia Objective 1.9) Flashcards
In Linux the command prompt utility is called what?
- Terminal or sometimes Xterm or similar.
- This is similar to the command prompt in Windows.
- Note Commands are similar in both Linux and macOS. This is because macOS derived from BSD( Berkeley Software Distribution) Unix.
If you want to see the manual for command line in Linux what command utility can you use to view it?
- “man”. This is an online manual for help using Linux’s command line.
- If you want to see a manual related to specific commands you would type something like “ man grep” to get a list of commands related to the “ grep” command.
Similar to Windows command prompt command “ dir” Linux also has a command to list the contents of a directory which is?
- ” ls” which stands for list directory contents. Similar to the dir command inn Windows
- This lists files, directories, may support color coding, Blue is for directory and red is an archive file and white is for a standard file, etc.
- For Long output with more info use the “ls -l” command and in order to tell the command to stop after 1 page of data before displaying on screen you can also can use the “ | more” to break the info down into pages. Use the command “q” or “ Cntrl-c” to exit
Just like in Windows you can use this command to change the current directory that you are viewing by typing what?
- “cd” Change current directory.
- Nearly identiccal to Windows Command line but you use forward slashes instead of backslashes.
- E.G to view the log directory in Linux you would use the command “ cd /var/log”
What is a super useful command that will allow you to search for a specific section of text in a file. Also allowing you to search many files at one time?
- “grep” find text in a file.
- E.G. to search for the text “ failed” in a specific file you would type “ grep failed [ File name plus file extension]
- Note the grep command utility is case sensitive so make sure you type the search name by exactly how it would appear.
Because certain actions commands in Linux will require elevated permissions( admin privileges) what command will provide you with those elevated rights?
- ” su” / “ sudo”. Some commands require elevated rights. As there are some things normal users can’t do.
- “su” command changes the user type to that of a super user. Or allows you to change to a different user. You continue to be that user until you exit the command line using the “exit” command.
- If you just wish to run a single command as a super user you can use the “sudo” command to execute that one specific command as the super user and than return to the normal user status after that command has been completed.
- An example of a command that would require elevated permissions of a super user status would be the ability to shut down the system using the “shutdown” command. This allows you to safely turn off the computer in software similar to the Windows shutdown command. So in this instance you would want to type the command “ sudo shutdown” or if you want the system to shutdown after a specified amount of minutes such as 2 minutes you would type “ sudo shutdown 2”
- If you want to be able to tell the system to shutdown and then reboot after 2 minutes you would type “ sudo shutdown -r 2” to achieve this. This is important to do when you’re not on site.
- In order to cancel the shutdown process you would have to use one of 2 commands either “ Cntrl-C” or “shutdown -c” depending on the Linux distribution. The command line will state which command to use to cancel the shutdown or reboot process. So full command would either be “ sudo shutdown -c” or “ sudo Contrl-C”
Because it can sometimes be hard in Linux command line to know exactly what directory you are currently inside of what command utility can you use to find out?
- “pwd” Which means Print Working Directory.
- Will display the current directory on screen inside of the command line. Displays the current working directory path.
- This is useful when changing directories often.
- Note this should not be confused with the command “ passwd” which allows you to change a user account password either yours or another’s. E.G. “ passwd [username]” or simply “ passwd” for your own password.
If you wanted to move a file or to rename it inside the command line what command would you use to achieve this?
- “mv”. Move a file or Rename a file.
- For example if you wanted to change the name of a text file called “ soccer.txt” to “football.txt” you would type the following command : “ mv soccer.txt football.txt”
- To move a file to a different location you would type “ mv “name of file” and then the directory path( E.G /home)
If you wanted to make a copy of a file or directory what command would you use in Linux to achieve this?
- ” cp” Copy a File. Duplicate files or directories.
- For an example to copy the text in a file to a new file you would type cp SOURCE DESTINATION. E.G. in order to copy the file “soccer.txt’ to a new file with the same data called “ football.txt” you would type “ cp soccer.txt football.txt”
In order to remove files or directories inside of Linux command line what command would you use?
- “rm” . Removes files or directories( Deletes the files)
- Note this does not remove directories by default. Directories must be empty to be removed first however you can use the “-r” command extension after the “ rm” command to tell it to delete the directory and all files inside as well.
If you wanted to create a directory inside of Linux command line what command would achieve this for you?
- “mkdir”. Make a directory. Creates a folder for file storage.
- For example if you wanted to create a directory named “manuals” you would type the command “ mkdir manuals”
What command in Linux would allow you to adjust the read, write and execute permissions associated with a particular file?
- “chmod”. Change mode of a file system object.
- Options for this are r = read, w=write, x=execute.
- You can also use octal notation to separate modes for invividual users and groups. Set for file owner(u), the group(g), others(o), or all(a).
- To change the read, write permissions for a file named “script.sh” in Linux command line where the User is allowed to read, write and execute that file, however the group should only be able to read it as would others you would type : “ chmod 744 script.sh”. This is because in Linux after the command “ chmod”
0 = no rights(—),
1 = Execute only(–x),
2 = Write only(-w-),
3= Write and Execute(-wx),
4= Read only(r–),
5= Read and execute(r-x),
6= Read and Write(rw-) and
7= Read, Write and Execute(rwx).
- This is because r=read, w=write and x= execute. So each group of users are assigned a 3 character long read and write permissions using this numbering and lettering scheme.
And the User’s 3 digits are displayed first, Then the groups, and finally Others. So for the string 744 after the chmod command the 7 would be referring to the User, the 4 to the group and the other 4 for others. So for this command is saying the User get’s full read, write and execute permissions(7 or r-w-x) whereas the group and others only have read permissions( 4 or r–) this can be verified by using the “ ls -l” command.
There are a number of shortcuts that can be used with the cdmod command such as?
- In the previous example we used the “ chmod 744 script.sh” command to specify that for that file the user had read, write and execute privileges whereas the group and others onl had read permissions.
- However this could be simplified by using the “ chmod a” command which tells it that this command will be associated with all users and then by typing “-w” after the “chmod a” command you will tell the system that there is to be no writing to script.sh. So full command would be “chmod a-w script.sh”
- Another example would be to tell the system to allow the owner of the file “ script.sh” to be able to execute it only. You could type “ chmod u+x” the “+x” tells the system that you want to add execute privileges and the “u” signifies the owner of the script.sh file.
What command would you use In order to tell the system in command line to change the user and group ownership of a file?
- “chown”. Change the file owner and group. Modify file settings.
- E.G. type “ sudo chown [OWNER:GROUP] file “ to tell the system to provide elevated permissions that will be required to change the file ownership to a particular group name which is provided and then the name of the file of which you are changing the ownership of.
- Another example would be to change the ownership of a file named “ football.txt” to be owned by a user named “professor” you would type the command “sudo chown professor football.txt”:
If you wanted to view the wireless network configuration of a system in Linux what command could you use?
- “iwconfig”. View or change a wireless network configuration.
- Things that can be viewed and changed include: essid, frequency/channel, mode, rate etc.
- Does require some knowledge of the wireless network.
- An example of a command you could use would be “ iwconfig eth0 essid studio-wireless” .iwconfig(lists the wireless network settings, eth0(names the NIC name) and finally the essid studio-wireless section tells the system to rename the SSID of the wireless connection to studio-wireless.