selfh.st: Command Corner
- There are some extremely useful commands here, & I just wanted to have them noted down somewhere.
tr -dc A-Za-z0-9_ < /dev/urandom | head -c 16 | xargs
- Use tr -dc A-Za-z0-9_ < /dev/urandom | head -c 16 | xargs to quickly generate a password from the command line (create a bash alias for quick reference in the future):
$ tr -dc A-Za-z0-9_ < /dev/urandom | head -c 16 | xargs
nfZY12B8v9ppdayQ
ls | wc -l
- Use ls | wc -l to quickly count the number of files & folders in the current directory:
$ ls | wc -l
8
for i in *; do test -d $i && du -sh $i; done
` Use for i in *; do test -d $i && du -sh $i; done to output a list of directories in the current folder and their sizes (skipping files and subdirectories):
$ for i in *; do test -d $i && du -sh $i; done
806M Development
...
2.1G Docker
56K Documents
44K snap
31G Syncthing
ls -lt
- Use ls -lt from the command line to quickly list files and directories by last modified time:
ls -t
- This will do the same as the above, except just lists the folder in order of last modified time, not including any extra information (permissions, size, date, etc)
history > commands.txt
- Use history > commands.txt to save the terminal’s command history directly to a file: