- Clean up the line: You can use Ctrl+U to clear up to the beginning.
- Clean up the line: Ctrl+A Ctrl+K to wipe the current line in the terminal
- Cancel the current command/line: Ctrl+C.
- Recall the deleted command: Ctrl+Y (then Alt+Y)
- Go at the beginning of the line: Ctrl+A
- Go at the end of the line: Ctrl+E
- Remove the forward words for example, if you are middle of the command: Ctrl+K
- Remove characters on the left, until the beginning of the word: Ctrl+W
- To clear your entire command prompt: Ctrl + L
- Toggle between the start of line and current cursor position: Ctrl + XX
pwdwill tell you what directory you're currently in.pushdtells the operating system "Remember this directory. I'm going to want to come back here." Optionally, you could saypushd ~which would store the current directory location, and then take you to your home directory (~).popdwill return you to the directory you just stored.
If you're in a given directory, typing ls will give you a list of the non-hidden files in that directory. Hidden files, you say? What's this hacker stuff? Any file that starts with a . is a "hidden" file. In your home directory (get there by doing cd $HOME or cd ~), you may have a file called .profile. This stores a bunch of information about your user. Hidden files are everywhere. Things to keep in mind with ls:
ls -awill show all files, including the hidden ones.ls -lwill show detailed information about the files, like when it was last modified, who owns it, what permissions it has, etc.ls -lhwill show the filesizes of the file in a human-readable format, like 1.2MB, 3.7K, etc.ls -lahwill do all three, of course.
Not surprisingly, find is the most powerful command to find stuff in Linux. Good things to remember:
-
find . -type d- looks in the current directory ( represented by.) and finds things of typed, which are directories. -
find . -name blah- looks in the current directory for files named blah. -
du -hs * | sort -h-du -hs *provides adiskusage summary, and the-hswitch makes ithuman readable, while the-sswitch provides a summary. If you don't add the*then it just summarizes the directory you're in with no detail by sub-directory. The pipe (|) into thesortcommand will arrange the results ofduby how large each directory is.
grep is one of the most powerfully badass commands in the world. Literally books have been written about it. But basically it will look, recursively if you want it to, into all the files in a given directory for some Regular Expression (see below) pattern that you define. So if you want to see every .log file that has error in it, you would run grep "error" *.log. Running that in this directory gets you this:
user@coolbox /dev/401ode/tools grep error *.md
tips-tricks.md:`grep` is one of the most powerfully badass commands in the world. Literally books have been written about it. But basically it will look, recursively if you want it to, into all the files in a given directory for some Regular Expression (see below) pattern that you define. So if you want to see every `.log` file that has `error` in it, you would run `grep "error" *.log`. Running that in this directory gets you this:
In the following example:
- -r - turns on recursion
- -i - means case-insensitive search
- --include=[filename/type] - includes only files that meet that pattern, in this instance only text files. 'searchterm' - obvious, but you don't need quotes around it.
- ./ - means search only in this directory.
grep -r -i --include=\*.txt 'searchterm' ./This regular expression has come in handy a ton of times when looking for some non-UTF8 character in a large CSV: [^\x00-\x7f]. Works like a charm in Visual Studio Code.
strings is a nifty tool to read a file and spit out only the legible characters within. At least four of them in a row, followed by some unprintable character. Helps to cut the wheat from the chaff. Example from PicoCTF 2018:
user@pico-2018-shell-2:/problems/strings_2_b7404a3aee308619cb2ba79677989960$ strings strings | grep pico
picoCTF{sTrIngS_sAVeS_Time_3f712a28}
user@pico-2018-shell-2:/problems/strings_2_b7404a3aee308619cb2ba79677989960$To start to play around with Regular Expressions, Regex101 is a great place to start. The "Quick Reference" box in the bottom right is great. There's also a quiz!
^- Start of a line$- End of a line\s- A Whitespace character.
- ipify is an easy, API-accessible way of figuring out what your external IP address is. So, in Powershell:
Invoke-WebRequest "https://api.ipify.org?format=json" -UseBasicParsing. Bash/ZSH version:wget https://api.ipify.org?format=json.
- So, there's a difference between having data in rows and columns and having a Table (note the capitalization). Tables are super-useful and we'll write more about them in the future, but in the meantime here's how to turn off Table headers.
More to come.