Bash commands Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

List contents of the directory

1) Display long form
2) Print one entry per line
3) Recursively list subfiles
4) Show hidden (dot) files

A

ls

1) ls -l
2) ls -1
3) ls -R
4) ls -a

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

Prints text to the cmd window

printf

A

echo

Improved echo that allows for formatting

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

Creates a file

A

touch

Update the access and modification times of each FILE to the current time

A FILE argument that does not exist is created empty, unless -c or -h is supplied

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

Create a directory

Create a directory with a subdir path

A

mkdir
Specify multiple directories
mkdir -p

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

Find out what a command does by printing manual or get help for a command

A

man

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

Print working directory

A

pwd

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

Change directory

1) One level up
2) Current Dir
3) Home Dir

A

cd

1) cd ..
2) cd .
3) cd ~

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

Move or rename a directory

A

mv

If filepath is the same, renames the file name

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

Remove empty directories

A

rmdir

Specify multiple directories

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

Locate a specific file or directory

A

locate

You can keep your search broad if you don’t know what exactly it is you’re looking for, or you can narrow the scope by using wildcards or regular expressions.

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

View the contents of a text file - displayed one page at a time

1) Go down
2) Quit
3) Go to the next file

A

less

Specify multiple filenames

1) spacebar to scroll down
2) :q
3) :n

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

Takes the output of a command and saves it to a file

A

Using the redirect operator >
echo Test > test.txt
head -n 5 filename.csv > head.txt

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

1) Read a file in CLI
2) Display contents with line numbers create a file, and concatenate files
3) Concatenate the outputs of two files and redirect it to a new file
4) Create a new file using the cat command

A

cat

cat -n

cat file1.txt file2.txt > combinedfile.txt

cat > file_name.txt
* type text, ENTER, ctrl + D to save the file

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

1) Print a list of commands run recently
2) Rerun a command based on its history number
3) Clear history

A

history

!600

history -c

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

1) Show lines containing specific values
2) Show lines that don’t match - invert the match
3) Print line numbers for matching lines
4) Print count of matching lines

A

grep

grep -v

grep -n

grep -c

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

Count the records in a file – lines

Count the records in a file – characters

Count the records in a file – words

Count records that match a term using pipe

A

wc -l

wc -c

wc -w

grep | wc -l

17
Q

Specify many files using a wildcard operator

A

folder/*

head -n 3 *.txt
Prints the first 3 lines of all .txt files

18
Q

Pipe | operator

A

Takes the output of a function and passes it as the input to another

19
Q

1) Reads the start of the file
2) Reads the end of a file
3) Specify number of lines to read

A

head -n 3

tail -n 3

Using the -n option

20
Q

Exit out of a session

A

exit

21
Q

Clear your terminal window

A

clear

22
Q

View current processes running in bash

A

ps

23
Q

Copy files / directories

A

cp old_name new_name

24
Q

Add a temporary alias

Remove an alias

A

alias c=”clear”

General syntax: alias =”command_name”

unalias

25
Q

Open up the nano text editor

1) Write out to a file name
2) Exit nano editor

A

nano

1) ^O
2) ^X

26
Q

Kill the current (foreground) process

A

^c

27
Q

Remove an entire directory

A

rm -rf

Recursive and force

28
Q

Search a previously executed command in the command history

A

^r then enter search terms

29
Q

View all environment variables

A

printenv

30
Q

Execute a shell script

A

./script_name.sh