or in other words, how to cat files from a long path directory
cd /media/home/user/usb/Documents/Linux/test.txt
cat test.txt | grep abc
How do I shorten this?
I tried with a script:
#!/bin/bash
var1="/media/home/user/usb/locuments/linux/test.txt"
var2="cat test.txt | grep abc"
"cat test.txt"=`var1 var2"
or
"cat test.txt"=`cat test.txt | grep abc`
LOL ... Obviously don't have even a basic knowledge about scripting
There should be some other ways of doing this
What would be the best method to use for this to work?
what do I start to search and try for?
If you always need to run that exact command, you can use an alias. Run
nano ~/.bashrc
and add this line to the file:Save the file, open a new terminal and you will now be able to just run
abc
and get your results.If you need to be able to search for different patterns, use a function instead. Again, run
nano ~/.bashrc
and add these lines (but delete the alias above if you have added it):Save the file, close it, open a new terminal and you can now run:
To search for the string
foo
in the file/media/home/user/usb/Documents/Linux/test.txt
. OrTo search for the string
bar
, etc.