Basic UNIX commands
Know more about a cmd use $man command
Directory
Show your Present Working Directory
Make a directory
Change directory
Return to your home directory
Return to the upper directory
Return to the root directory
Will show you all files with the 'extension'
Will show you all files with the 'string'
- grep string filename(s)/grep [options] pattern [files]
Looks for the string in the files (txt file typically).
e.g.,
$grep python grep_example.txt
txt file (cat grep_example.txt)
-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option. Can use multiple times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line,
with each such part on a separate output line.
-A n : Prints searched line and nlines after the result.
-B n : Prints searched line and n line before the result.
-C n : Prints searched line and n lines after before the result.
Examples,
File
Lists your files
lists your files in 'long format', which contains lots of useful information, e.g. the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified.
lists all files, including the ones whose filenames begin in a dot, which you do not always want to see.
There are many more options, for example to list files by size, by date, recursively etc.
Create a new file
e.g., $touch grep_example.txt
Delete a file
Copies a file
Shows the first part of a file, just as much as will fit on one screen
Just hit the space bar to see more or q to quit. You can use /pattern to search for a pattern.
More examples https://shapeshed.com/unix-more/
Lets you change the read, write, and execute permissions on your files.
The default is that only you can look at them and change them, but you may sometimes want to change these permissions.
For example, chmod o+r filename will make the file readable for everyone,
and chmod o-r filename will make it unreadable for others again.
Note that for someone to be able to actually look at the file the directories it is in need to be at least executable.
More https://www.geeksforgeeks.org/chmod-command-linux/
Other
- export variable=value (now space before and after =)
$export mytestpath = test123
Shows the value of an environment variable
$echo $mytestpath
>>test123
cleans screen
You need to source your dotfiles after making changes for them to take effect (or log off and in again)
More Unix commands
https://mally.stanford.edu/~sr/computing/more-unix.html
https://mally.stanford.edu/~sr/computing/basic-unix.html