Linux Flashcards

1
Q

Check memory usage

A

free -h shows all free memory

du -h -d 1 (disk usage, human, depth =1) meaning the depth of folders it will look.

df -h shows how much memory each directory is consuming in human readable form

Du -a -h -d 1 shows you all the files, hidden files, and directories disk usage

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

Find text in a directory

A

grep /path/to/file -e text-to-search

grep /path/to/dir -e text-to-search

grep -rnw /path/to/dir -e text-to-search

  • r or -R is recursive,
  • n is line number, and
  • w stands for match the whole word.
  • l (lower-case L) can be added to just give the file name of matching files.
  • e is the pattern used during the search
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Read file to console

A

cat

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

Open file to edit

A

vim

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

In vim

quit file, save quit, edit file, how to stop editing

A

:q!, :q, :wq, [i] for insert, escape to stop editing

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

print files in dir

A

ls, ls -al shows all hidden files with permissions

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

move file, make directory, remove directory, make file

A

mv file1 file2
mkdir dirName
rmdir dirName
touch file

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

find a file

A

find /dir/ -name file.txt

searches for the file in the dir and sub dirs

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

read beginning or end of files

A

head -n file.txt

tail -n file.txt

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

See differences between 2 files

A

diff file1 file2

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

remove file, remove directory, remove directory and all sub files/dirs

A

rm file, rmdir dirname, rm -rf dirname

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

create a tar file, unzip a tar file

A

tar -cvf name.tar dirname/or/filename

  • c create tar
  • v verbose
  • f specify file name

tar -xzf tar.gz

  • x extract
  • z gzip, gunzip, ungzip,
  • f file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

change read-write permissions, change owner

A

chmod filename

chown newowner:newgroup filename

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

show all jobs running and their statuses. Jobs are started by the shell

A

jobs

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

stop a process

A

kill -9/-15 PID

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

download a file given a link

A

wget download-link

17
Q

check linux system information such as machine name, operatin system, kernel

A

uname

cat /proc/cpuinfo

18
Q

task manager but for linux

A

top

19
Q

see a list of previous commands run

A

history

20
Q

get a list/help with linux commands

A

man

21
Q

check ip address

A

ip addr

hostname -i

22
Q

how to copy a file, directories, while preserving file state?

A

cp file1 file2 – copies file1 to file2

cp file1 file2 new – copies file1/file2 into new dir

cp -R dir1 dir2 – copies all files from dir1 into dir2. If dir2 exists it will make a subdir of dir1 in dir2, if it does not exist it will create dir2

-p option preserves all information about the file, time of last edit, permissions, ect

23
Q

monitor a process on the system

A

ps aux | grep

24
Q

do 2 tasks at once in a single line

A

use &&

cd /home && ls - al
cd’s to home and executes ls -al

25
Q

how to use scp on, copy a file from a remote location or copy to a remote location

A

Linux file -> windows
Scp user@domain:
Windows -> linux
Scp user@domain:

**to go from linux to windows, you need to set up an scp server on windows. This is not default

26
Q

check network traffic

A

tcpdump

tcpdump -i any
or

there are many ways to use this command

27
Q

list of linux file permissions you can set
example:
chmod filename

A

400: Gives the user read permission, and removes all other permission. These permissions are specified in octal, the first char is for the user, second for the group and the third is for other
755: means read and execute access for everyone and also write access for the owner of the file. … So, there should be no permission to everyone else other than the owner to write to the file, 755 permission is required.

28
Q

sed, stream editor command

A

https://www.geeksforgeeks.org/sed-command-in-linux-unix-with-examples/

$cat > geekfile.txt
unix is great os. unix is opensource. unix is free os.
learn operating system.
unix linux which one you choose.
unix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.
Sample Commands

Replacing or substituting string : Sed command is mostly used to replace the text in a file. The below simple sed command replaces the word “unix” with “linux” in the file.

$sed ‘s/unix/linux/’ geekfile.txt

this replaces the first ‘unix’ per line with ‘linux

$sed ‘s/unix/linux/g’ geekfile.txt
makes replacements for all found characters

$sed ‘s/unix/linux/3g’ geekfile.txt
replaces the 3rd