Basic Linux commands for devs (flipped) Flashcards

1
Q

use to get more details about the specified command and arguments that can be used with it

A

man {command}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

“Present working directory”. prints the path to the current directory

A

pwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

used to open the specified file or internet URL

A

open {filename/url}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

list all files and folders in the current directory

A

ls

-a : adds hidden elements
-l : long format (adds more information)
-al : does both

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

used to create a new folder/directory

A

mkdir {name}

can also make multiple at once by adding space separated names ex.
mkdir folder1 folder2 folder3

-p: create nested folders
ex:
mkdir -p foler1/nested

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

used to create new files.

A

touch {name}

ex:
touch file.txt
touch file.txt file2.py

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

used to remove empty folders

A

rmdir

ex:
rmdir folder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

used to remove empty or non-empty folders/directories/files

A

rm

ex:
rm file.txt
rm -d empty_folder
rm -r non_empty_folder
rm -r * (removes all files/folders in current directory)

note:
files will not be moved to recycle bin, it is a permanent deletion.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

used to copy files into the target folder

A

cp {file} {folder}

ex:
cp file1.txt folder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

used to move files into the target folder

A

mv {file} {folder}

ex:
mv file1.txt folder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

used to show all commands that have been typed into the Linux shell.

A

history

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

used to show the difference between two files

A

diff {file1} {files2}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

used to show the first {10 lines default} of a file

A

head {filename}

ex:
head -n 15 logfile.txt
{will show the first 15 lines of logfile.txt}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

used to show the last{10 lines default} of a file

A

tail {filename}

ex:
tail -n 15 logfile.txt
{will show the last 15 lines of logfile.txt}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

used to print messages/variable values to the terminal.

A

echo {msg/$variable}

ex:
echo $username
{prints value of username}

echo *.txt
{prints all txt files in the dir to terminal}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

pings the given address to check connectivity.

A

ping {url / IP address}

note:
will run indefinitely every second until killed with {cntrl + C}

17
Q

change the current working directory.

A

cd {path}

cd ../ : moves up one level to parent directory

18
Q

print the contents of a file to the console. Can also append or overwrite file contents between two files.

A

cat {filename}

“short for concatinate”

cat >{filename}
{file contents} : will create a new file with the contents inside

cat {file1}&raquo_space; {file2.txt} : will add the contents of file1 to file2.

cat {file1} > {file2.txt} : will copy and OVERWRITE contents of file1 into file2

19
Q

Display a real-time list of processes running on the machine (similar to task manager on windows)

A

top

note: will run until you hit “q”

20
Q

used to set up shorthands of commands used frequently to avoid retyping.

A

alias {alias name}=”{command}”

21
Q

used to remove a shorthand for a command that was set up previously.

A

unalias {alias name}

22
Q

allows you to view files without opening an editor.

A

less {filename}

23
Q

create, view, and edit files in the terminal window.

A

nano {filename}
input/edit file contents -> “Cntrl + X” -> “y” to save.

24
Q

create, view, and edit files in the terminal window WITH VIM.

A

vim {filename}
input/edit file contents -> “Cntrl + X” -> “y” to save.

25
Q

search the contents of a file for a specified pattern.

A

grep {pattern} {filename}

grep -n {pattern} {filename} : print the line number where pattern is found.

grep -c {pattern} {filename} : count number of pattern occurrences.

26
Q

find the location of files that contain the given pattern in their name.

A

find {location} -name “{filename}”

ex:
find . -name “*py” : find all files and their locations that contain “py” starting at root directory.

27
Q

compress a target file/folder into a zip file

A

zip {compressed filename} {target folder/file}

28
Q

unzip a target file

A

unzip {target zip filename}

29
Q

show the disk usage of files and/or folders

A

du -h

du -h : all files/folder in working directory
du -h {file/folder} : usage of specified target

30
Q

used to retrieve files from specified URL or IP address

A

curl {address} : this will fetch contents of the file without saving them

curl -o {new filename} {address} : will fetch contents and save them into a new file.

31
Q

change the owner or user group associated with a file/directory

A

sudo chown {username} {target file/folder}

sudo chown :everyone {target file/folder} : will change the user group associated to everyone.

sudo chown {username}:{group name} {target file/folder} : will change both username and user group.

32
Q

used to modify the permissions or file modes associated with different files or directories.

A

chmod {user/group/other} {operation}{permissions}

{user/group/other} u=user, g=group, o=all others.
{operation} +(add permission) -(remove permissions) =(set permissions to)