# Listing `~$ ls -a` - shows directories and folders. `-a` shows hidden files. # Change directory `~$ cd ./Documents/pics` - swap to a directory `~$ cd ..` (go up a folder) # Concatenate `~$ cat /home/ubuntu/documents/todo.txt` - outputs contents of a file - head outputs a shorter version if file is large asf - tail outputs the end of it # tree `tree .` - outputs the filesystem in a tree structure # less/more `tree . | less` - this will display the file in pages, use arrow keys or page up/down to move thru `tree . | more` - this ONLY allows you to go down # head/tail `head -n10 myfile` - displays the top 10 lines in myfile - change -n{#} to suit needs `tail -n10 myfile` - dispalys the last 10 lines in myfile - again, change the -n{#} to suit needs # Print working directory (present) `~$ pwd` - full path to current working directory ## Searching for Files # find `~$ find -name passwords.txt` - find a name of that file in current directory `~$ find -name *.txt` - finds everyfile in current directory with .txt extension - the * is wildcard `find {where-to-search} {search-criteria}` Common options: - `-name` - `-type` - file type (.txt .pdf) - `-perm` - find with given permissions like 777 # grep `~$ grep "THM*" access.log` - search the contents of a given file for specific values. E.G. an access log - grep is commonly piped in with other commands to find something within a command out put. `cat /etc/passwd | grep nologin` using grep and cut to pull out what i want from a file `stat textfile` - there is alot of data here, lets say i just want the last modify date `stat textfile | grep 'Modify'` - now this just shows us the modify line `stat textfile | grep 'Modify' | cut -d\ -f2,3` - now this will cut out everything else since we deliniated that the space was what was between fields with `-d\ ` and then says we want fields 2, and 3 `stat textfile | grep 'Modift' | cut -d\ -f2,3 | cut -d\. f1` - finally we deliniated the "." as the symbol separating the fields and told it we wanted only f1. Now the output is: `2023-04-19 09:25:06` `grep --text '^\=' data.txt` --text forces grep to read a file as regular text, for example if the file is binary but has cleartext hidden among it # sort pipe it into something and it will sort alphabetically `grep xxx | sort` # uniq pipe it into something and it will only show unique values `grep xxx | sort | uniq` links: [[_LinuxTerminalCMDIndex]] tags: #linux #terminal #CMD