Unix Command Line
Going through this guide: GitHub - jlevy/the-art-of-command-line: Master the command line, in one page and going to take note on notable thing as I go.
Tips:
- Use
curl cheat.sh/<command>
for a cheat sheet on whatever command you’re not sure about. awk
202211260214 is extremely useful for programmatically processing / applying some sort of function to a file line by line.less
202211260215 is a pager, which makes is to that you don’t have to load a file completely into memory to read it (which is what Vim does). Most of Vim commands still apply, withctrl-f
to go one page forward andctrl-b
to go one page backward.- Globbing is important. Reference link:
- https://mywiki.wooledge.org/glob https://www.wikiwand.com/en/Glob_(programming)
*
is zero or more characters?
is exactly one character[abc]
matches one character in the bracket- Globbing in SQL:
_
=?
and%
=*
.
- Bash job management 202211260219
- appending an
&
to a process will make it run while still allowing you to enter input into the console. fg
andbg
will move the most recent process into the foreground or background respectively.- If you want to kill a job with a certain id (found in
jobs
, for example), then usekill %{job_id}
. Awk
202211260214- For a quick summary of disk usage:
du -hs *
- appending an
Less
202211260215 follow-mode, to see how a file grows:less +F <file>
- Regular expressions 202211260228 (
grep
/egrep
):- Flags to be aware of:
-i
: ignore case-v
: Invert match. Select lines that don’t match the specified patterns-o
: prints only the matching part of the line-A
,-B
,-C
, number of trailing lines of context before/after/before+after each match.
- Flags to be aware of:
Awk
202211260214 can be used withsed
for text manipulation.- Last one for today! What do the columns in
ls -l
mean?- file mode, number of links, owner name, group name, number of bytes in the file, abbreviated month, day-of-month file was last modified, hour file last modified, minute file last modified, and the pathname.
- The file mode printed under the -l option consists of the entry type and the permissions. The entry type character describes the type of file, as follows:
- Regular file. b Block special file. c Character special file. d Directory. l Symbolic link. p FIFO. s Socket. w Whiteout.
- [Note: the section above isn’t super helpful. I don’t see a situation where this will be very useful, so I’m not going to view it for now.]
- file mode, number of links, owner name, group name, number of bytes in the file, abbreviated month, day-of-month file was last modified, hour file last modified, minute file last modified, and the pathname.
- Advantages vs. disadvantages of soft links (symlinks)
- Create a soft link:
ln -s file1 link1
- While useful, there are some limitations to what hard links can do. For starters, they can only be created for regular files (not directories or special files). Also, a hard link cannot span multiple filesystems. They only work when the new hard link exists on the same filesystem as the original.
- All of this sounds great, but there are some drawbacks to using a soft link. The biggest concern is data loss and data confusion. If the original file is deleted, the soft link is broken. This situation is referred to as a dangling soft link. If you were to create a new file with the same name as the original, your dangling soft link is no longer dangling at all. It points to the new file created, whether this was your intention or not, so be sure to keep this in mind.
- Create a soft link:
- Things to look at in the future:
chown
,chmod
- for filesystem management:
df
,mount
,fdisk
,mkfs
,lsblk
- for filesystem management:
- Keybindings in bash (and also zsh): These are all emacs keybindings!
- Ctrl-w to delete the last word
- Ctrl-u to delete content from cursor to start of the line. Ctrl-k to kill till end of line.
- Alt-b to move back one word, and alt-f to move forward.
- Ctrl-a to move cursor to beginning of line.
- Ctrl-e to move cursor to end of line.
- Ctrl-l to kill the screen.
- If you are halfway through typing a command but change your mind, hit alt-# to add a # at the beginning and enter it as a comment (or use ctrl-a, #, enter). You can then return to it later via command history.
uid: 202211260212 tags: #software-engineering