Difference between revisions of "Unix Commands"

From Steak Wiki
Jump to navigationJump to search
 
(2 intermediate revisions by the same user not shown)
Line 11: Line 11:
 
  alias hs="history"
 
  alias hs="history"
  
 +
<pre>
 +
function cd() { builtin cd "$@"
 +
 +
if [ -f README ]
 +
then
 +
    cat README
 +
fi }
 +
</pre>
 
===Useful but less intuitive commands===
 
===Useful but less intuitive commands===
 
To get file counts for all directories (say you want to know how bloated / lean a software project is)
 
To get file counts for all directories (say you want to know how bloated / lean a software project is)
Line 18: Line 26:
 
Resources: Unix Power Tools 1993
 
Resources: Unix Power Tools 1993
  
 +
Here's a test command.
 +
 +
ANS=$(ls -l | wc -l)
 +
su username -c "test ${ANS} -gt 10 && beep"
 +
watch "su username -c 'test ${ANS} -gt 10 && beep'"
 +
watch "su username -c 'test `ls -l | wc -l` -gt 10 && beep'"
 +
watch myscript.sh
 +
 +
1) In order to get a command to run in test, wrap it in a variable
 +
 +
2) There is a syntax trap: you don't run $ANS, but ${ANS} in test
 +
 +
3) beep is a piece of $#@% and won't run as root, so run it as a user with su
 +
 +
4) you have to use the right order of escaping quotes.
 +
 +
5) for some reason, watch isn't running a new command everytime.
 +
 +
6) the answer is to put the watch command in a shell script. then it will re-evaluate it.
 +
 +
7) done.
 +
 +
The quoting in this is, not great.
  
 
==External Links==
 
==External Links==
* https://lowendbox.com/blog/ten-cool-linux-command-line-tricks-for-the-journeyman-practitioner/ - A similar list. Somehow I missed the timeout command.
+
* https://lowendbox.com/blog/ten-cool-linux-command-line-tricks-for-the-journeyman-practitioner/ - A similar list. Somehow I missed the timeout and script command.

Latest revision as of 08:55, 3 January 2026

some years of gnulinux, commands i have found easy to understand, yet still useful


find . -print | grep <somefile>
find . -printf '$TY-%Tm-%Td %p\n' | grep 2020-12-29
stat /files/* | grep -A5 <somenameoffile>  | awk 'xor(/File/,/Modify/)' > /tmp/dates
sed -e 's/original/new/g' -i editfileinplace.txt
grep 'one|two|three'  -search multiple items (may want to add -i to ignore case)

edit .bashrc

alias hs="history"
function cd() { builtin cd "$@"

if [ -f README ]
then
    cat README
fi }

Useful but less intuitive commands

To get file counts for all directories (say you want to know how bloated / lean a software project is)

du -a | cut -d/ -f2 | sort | uniq -c | sort -nr


Resources: Unix Power Tools 1993

Here's a test command.

ANS=$(ls -l | wc -l)
su username -c "test ${ANS} -gt 10 && beep"
watch "su username -c 'test ${ANS} -gt 10 && beep'"
watch "su username -c 'test `ls -l | wc -l` -gt 10 && beep'"
watch myscript.sh

1) In order to get a command to run in test, wrap it in a variable

2) There is a syntax trap: you don't run $ANS, but ${ANS} in test

3) beep is a piece of $#@% and won't run as root, so run it as a user with su

4) you have to use the right order of escaping quotes.

5) for some reason, watch isn't running a new command everytime.

6) the answer is to put the watch command in a shell script. then it will re-evaluate it.

7) done.

The quoting in this is, not great.

External Links