nix-config/help/commands.md

247 lines
11 KiB
Markdown
Raw Normal View History

2017-11-05 04:32:42 +01:00
## Common Commands
- Move files: `mv <source> <dest>`
- Move directories: `mv -r <source> <dest>`
- Copy files: `cp <source> <dest>`
- Copy directories: `cp -r <source> <dest>`
- Copy all files from one directory to an existing directory (includes dotfiles and subdirectories): `cp -R dir_1/. dir_2/`
2017-11-05 04:32:42 +01:00
Note that "renaming" files is the same as moving them from one location to another. For example, if you want to rename a file `oldfile` to `newfile`, then you would type `mv oldfile newfile`.
- Print the contents of a file: `cat <filename>`
- Batch rename multiple files: `rename -v <find_this_string> <replace_with_this_string> <in_these_files>`
- Remove (delete) files: `rm <filename>`
- Remove (delete) a directory: `rm -r <dirname>`
- Make a new file: `touch <filename>`
- Make a new directory: `mkdir <dirname>`
- List all the files in a directory: `ls` **OR** `find`
- List all the directories in a directory: `ls -d */`
- List all the files in a directory, including dotfiles: `ls -A`
- List all the files in dirname: `ls <dirname>`
- Only list png and jpg files: `ls *.{png,jpg}`
- Print the file type based on header information: `file <filename>`
- Show all running processes as a tree: `pstree`
- Print the number of lines in a file: `wc -l <file>`
- Print the length of the longest line in a file: `wc -L <file>`
- Print the number of words in a file: `wc -w <file>`
- Print the number of lines in all markdown files in a given directory, including subdirectories: `find . -name "*.md" | xargs wc -l`
- Show the size of the current directory, including subdirectories: `du -h`
- Show the size of the current directory and its files: `du -ha`
- Get more information about any command: `man <command>`
## Switching Directories
2017-11-06 03:41:01 +01:00
- Go up one directory: `..`
- Go up two directories: `...`
- Go to the home directory: `~` OR simply `cd` with no parameters
- Go to dirname: `dirname`
Note that for all of the above, `cd` is not required.
### Other Commands
- Print the working directory: `pwd`
- Termite the processes with a specific word in it: `killall -q <word>`
2017-11-06 07:29:33 +01:00
- Get the current time and settings: `timedatectl`
- Show what gets executed when you run a command: `which <command>`
- Create a symbolic (soft) link between two files: `ln -s <source> <dest>`
- When a program references `dest`, it will link to and give `source`.
- In comparison, a hard link is when you make a copy of the file
- Give permissions to the user `hello` and the group `world`: `chown -R hello:world dir/`
- Given text input, return only unique lines (aka no duplicates): `cat <input_file> | uniq`
2017-12-09 05:52:48 +01:00
- Search for a particular font on the system: `fc-list | grep -i <font>`
- Search for all files of a specific extension in a given directory: `find . -name "*.ext" -type f`
- Chain `-delete` to the end of the find command in order to delete the results
- This is useful if, for example, you want to delete all files with the extension `ext` in all directories and subdirectories
2017-11-22 23:21:17 +01:00
### Changing File Permissions
- Make a script executable: `chmod +x <file>`
- Change the permissions of a directory to all users: `chmod -R a+rwX dir/`
- Give anyone and everyone access to a directory: `chmod -R 777 dir/`
- Useful for deleting files that the current user can't delete
Note that you should *never* give a file or directory more permissions than needed. `a+rwX` and `777` should only be used in extreme situations where you have to change permissions before using a file. You should change the permissions back or delete the file when you're done.
2017-11-22 23:21:17 +01:00
### Searching Through Files
- Search all files in a directory (and all subdirectories) for a given string: `grep -inr <search_term>` **OR** `g <search_term>`
- Search all files in a directory (including subdirectories) for a given string and ignore dotfiles: `rg <search_term>`
### System Commands
- Logout of the current user session: `logout`
- Restart the system: `reboot`
- Turn off the computer: `poweroff`
## Installed Commands
These programs are installed on top of the base system.
- List the entire contents of a directory: `tree`
- List all the directories in a directory, up to 2 levels deep: `tree -d -L 2`
- Beautify any JSON output: `<json_output> | jq '.'`
- Easily search for a file in a directory and its subdirectories: `fzf`
2017-11-24 23:39:35 +01:00
- Show duplicate files in a given directory, with the ability to remove them as well: `fdupes <dir>`
- Add `-r` to go through subdirectories
- Add `-n` to exclude empty files
- Add `-f` to omit the first file in each set of matches
- Add `-1` to list each set of matches on a single line
- Add `-S` to show the size of each duplicate file
- Add `-d` to delete duplicates during execution
- Add `-A` to ignore hidden files
### Inox
- Open a webpage in a borderless window: `inox --app=<url>`
- Open a webpage in the regular browser window: `inox <url>`
2017-11-08 02:57:50 +01:00
### Waterfox
- Open a webpage in a new window: `waterfox --new-window <url>`
- Open a webpage in a new tab: `waterfox --new-tab <url>`
- Search for a specific term: `waterfox --search <term>`
2017-11-21 00:32:08 +01:00
### Jekyll
- Start a server and monitor it for changes (useful for development): `jekyll serve`
- Start a server and detach it from the current shell: `jekyll serve --detach`
- Terminate a jekyll server that was detached from the shell: `kill -9 <pid>`
- Terminate all jekyll servers: `pkill -f jekyll`
Note that you can run multiple servers on different ports through Jekyll and other software.
### Crystal
- Build and run the program directly: `crystal <file>`
- Compile the program to binary: `crystal build <file>`
- Add `--progress` or `-p` to show build progress
- Add `--release` when you're building the release version (takes longer)
- Add `--no-debug` to increase the build speed (useful for dev builds)
- Add `-o` to specify the location of the output file
2017-11-30 06:29:12 +01:00
### LaTeX
- Make a pdf of your document: `pdflatex <file>`
- Add `-output-directory <dir>` to specify the location for build files (`.aux`, `.pdf`, `.log`, etc.)
- The directory `<dir>` must exist before you can write to it
- Note that all `pdflatex` options must come before specifying `<file>`
2017-12-12 05:46:54 +01:00
### Xclip
**Using the X clipboard**
- Copy the result of any command to the X clipboard: `command | xclip`
- This is particularly useful for commands like `fzf`, where you want to search for a specific file then do something with it
- Paste the results from the X clipboard: `xclip -o`
**Using the global clipboard**
- Copy a file to the global clipboard: `xclip -sel clip < filename.txt` **OR** `cat filename.txt | xclip -sel clip`
- Note that `-sel` is shorthand for `-selection` and that `clip` is shorthand for `clipboard`
- Copy the result of any command to the global clipboard: `command | xclip -sel clip`
- Paste the results from the global clipboard: `xclip -o -sel clip`
2017-12-16 05:26:40 +01:00
### Secure Shell
- Make a new 4096-bit RSA key: `ssh-keygen -t rsa -b 4096 [-C <comment>]`
- Note that `id_rsa` is your private key and `id_rsa.pub` is your public key
- Add your new key to SSH: `ssh-add ~/.ssh/id_rssa`
- Copy your public key: `xclip -sel clip < ~/.ssh/id_rsa.pub`
- Add a location to your known hosts: `ssh -T <location>`
- For example, if you wanted to use SSH with GitHub, you would add the location `git@gitlab.com`
- Start the SSH agent: `eval "$(ssh-agent -s)"`
Note that a git repository must be cloned with SSH if you want to use SSH with it.
### Dealing with Archives
2017-12-30 05:50:11 +01:00
- Zip all files in a directory: `zip -r <zip_name> <directory>`
- View the contents of rar files: `unrar lb <files>`
- Extract the contents of rar files: `unrar x <files>`
- Extract the contents of zip files: `unzip <files>`
- Extract the contents of a tgz file: `tar -xvzf file.tgz`
- Extract any type of archiving algorithm: `extract <filename>`
2017-11-05 04:32:42 +01:00
**Note**: When using `unrar` or `unzip` to extract multiple files (with wildcards), you must first escape the `*` to `\*`.
2017-11-06 07:29:33 +01:00
### Opening Things
Note that the preferred way to open things is with the `open` function; however, sometimes it is necessary to use these commands if, for example, you're loading an entire directory.
- Open a video or multiple videos in a playlist: `mpv <files/dir>`
2017-11-29 03:42:40 +01:00
- Open an image or multiple images: `feh <files/dir>`
- Add `-r` to recursively iterate through all subdirectories
- Add `-z` to randomize the order of the images
- Use `-l` to enable list mode, an easy way to see various details about images
- Use `-t` to enable thumbnail mode, a quick and easy way to see all the images in a directory
- Add `-E <pixels>` to set the thumbnail height
- Add `-y <pixels>` to set the thumbnail width
- Note that generating thumbnails takes time (i.e. don't use with large file sizes)
2017-11-06 07:29:33 +01:00
### Firejail
Use `firejail` to sandbox a program or other piece of software. This ensures that the program does not have access to your entire file system since it runs in a restricted environment.
- Run a program in firejail with its default profile (if it exists): `firejail <program>`
- Use firejail by default for all programs that have profiles: `firecfg`
- List all the programs that use firejail by default: `firecfg --list`
- Remove all symbolic links to firejail: `firecfg --clean`
- Verify that firejail is being used for a particular program: `firejail --list`
2018-01-14 05:38:54 +01:00
### ImageMagick
- Resize an image to 50% of its original size: `convert -resize 50% <given_img> <output_img>`
- Resize an image to a specific size: `convert -resize 1280x720 <given_img> <output_img>`
- Resize all png files in a directory to 800x600: `mogrify -resize 800x600 *.png`
Note that you should use `mogrify` instead of `convert` when you want to change images directly.
### Pacman
2017-11-06 07:29:33 +01:00
Although the examples below use `pacman`, they apply for `yay` as well.
- Install packages: `pacman -S <packages>`
- Remove packages (including dependencies no longer needed): `pacman -Rs <packages>`
- Update all packages: `pacman -Syu`
- Search for a specific package: `pacman -Ss <package>`
- List all installed packages: `pacman -Q`
- List all the packages installed as dependencies: `pacman -Qd`
- List all self-installed packages (i.e. from the AUR): `pacman -Qm`
- Display information about a specific package: `pacman -Qi <package>`
- List all the files owned by a specific package: `pacman -Ql <package>`
- Install a package from a local file: `pacman -U /path/to/pkg.ar.gz`
2017-11-06 07:29:33 +01:00
Note that if you ever get 404s with `pacman` or `yay`, you need to update your local database to the new download locations with `-Syu` first.
2017-11-06 07:29:33 +01:00
#### Yay-specific Commands
- Remove unneeded dependencies: `yay -Cd`
- Show statistics about installed packages: `yay -Qstats`
#### Other Pacman Variants
- View the dependencies of a package in tree format: `pactree -c <package>`
- Add `-d 1` to limit the depth of the tree to one level deep
- List all the packages that depend on a certain package: `pactree -rc <package>`
- Remove all cached versions of packages except the most recent one: `paccache -rk1`
- Remove all cached versions of uninstalled packages: `paccache -ruk0`
### Working with Online Resources
- Download anything online: `wget <url>`
- View the response header and contents of any webpage: `http <url>`
2017-11-06 07:29:33 +01:00
## Custom Commands
- Easily switch to a 4k resolution with DPI scaling: `4k`
- Easily switch to a 1080p resolution (with 96 DPI): `1080p`
- Run a command as root: `pls <command>`
- Run the previous command as root: `pls !!`
## Startup Commands
- Turn the screensaver off and disable DPMS: `xset s off -dpms`
- Sync the system time with one on the internet: `sudo synctime`
- Launch Polybar `~/.config/polybar/launch.sh`