Linux tricks I use in day to day work
Hey,
I would like to share few of my Linux tricks and commands I use in day to day work. I know everyone has own best practices but I hope that maybe some of the following will be useful for you too ;-)
1. rm: cannot remove file: Permission denied
When you executed command but forget about sudo ;-)
$ rm file_to_remove
rm: cannot remove 'file_to_remove': Permission denied
$ sudo !!
sudo rm file_to_remove
!! - repeats the last command in Bash
2. Vim: E212: Can't open file for writing
You get permission error when trying to save recent changes... sounds familiar? Do you know you can use sudo directly from Vim?
:w !sudo tee %
3. ctrl+r, search in bash history
When you run commands in console, Bash save the history in a .bash_history file. If you want to re-run particular command but you don't remember the exact syntax, you can search for it,
ctrl+r
(reverse-i-search)`': part_of_the_command_you_are_searching_for
click ctrl+r again for the next result ;-)
alternative way is running: history | grep part_of_the_command_you_are_searching_for
4. Where to find the ascii table?
Do you know the ascii table is already in manual page?
$ man 7 ascii
5. Config file backup
If you're going to edit any configuration file it's always a good practice to make a backup of the file. Usually we run,
$ cp config.cfg config.cfg.bak
but there is a quicker way ;-)
$ cp config.cfg{,.bak}
6. Back to the previous directory
If you changed the directory to another and want to back to the previous one, you can run
$ cd -
This works because Bash keep the current and previous locations in $PWD and $OLDPWD environment variables.
7. Generate test file with particular size
If you need test file with particular size, you can use dd tool,
$ dd if=/dev/zero of=file count=1024 bs=1M
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 13.2885 s, 80.8 MB/s
- if is the source file/device (/dev/zero is block device which prints "0" characters)
- of is the output file/device name
- count is for the number of blocks we want to write,
- bs is the block size,
8. Delete files older than X...
If you want to delete files older than X days from directory, you can use a tool called find.
$ find /var/log/myapplication/ -type f -mtime +100 -delete
this simple command will remove all files older than 100 days from /var/log/myapplication/.
Please let me know if this is something you would like to read in future and don't forget to share your tricks and commands in comments ;-)
$ logout
Posted on Utopian.io - Rewarding Open Source Contributors
Leave Linux tricks I use in day to day work to:
Read more #utopian-io posts
Best Posts From Patryk Kuźmicz
We have not curated any of jamzed's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Patryk Kuźmicz
- The other reason why you should vote for the right witnesses ;-)
- Witness update 8/27/19 (HF21)
- jamzed witness update 9/30/18
- Do I really need 64GB of RAM for my witness nodes?
- Ugly Bash script does the job
- My random thoughts as a witness...
- jamzed witness update 1/28/18
- What is behind the Steem bandwidth issues...
- 🇵🇱 Dlaczego czasami dostajesz błąd "Bandwidth limit exceeded"?
- How to fix 'Connection to steemd.steemit.com timed out'