Is there an easy way to retrieve under Cygwin the volume label of an external disk or usb stick, given that I know the drive letter?
I know that I can do from my shell (actually zsh) i.e. a
cmd /c dir f:
and parse the output, but this is not only ugly, but also has the drawback that the output of the DIR command is language specific, i.e. I can't parse for certain keywords in the output.
I wonder if there maybe is a command in Cygwin which would provide the desired information?
Using the csihpackage:
$ /usr/lib/csih/getVolInfo.exe /cygdrive/d | grep Name
Volume Name : <DATA>
$ /usr/lib/csih/getVolInfo.exe /cygdrive/e | grep Name
Volume Name : <RECOVERY>
Related
I have only two folders under a given directory. Is there any method to choose the second directory based on the order and not on the folder name?
Example: (I want to enter under doc2)
#ls
doc1 doc2
If you really want to use ls,
cd "$(ls -d */ | sed -n '2p')"
selects enters the second directory listed by it, independently of the number of directories provided by ls.
Parsing ls output is not a good idea generally, although it will work in most cases and will cause no harm if you are just using it in your interactive shell for fast navigation. You should not use this for serious programming.
You can use the tail command to get the last line
ls |tail -1
I need to find a string in the entire Linux file system and I used grep to find all instances of this string in the filesystem. I got two types of results: one from my /.bash_history and another set of results from the proc directory. It is heavily hinted that the answer lies in some kind of process.
The /proc result looked something like this:
Binary file /proc/12345/task/12345/cmdline matches
When I try to navigate to directory 12345, it does not exist. I read in the redhat manual that files in /proc filesystem tend to be virtual. I'm guessing that the process might have ended by the time grep finished its search and I navigated around to the appropriate directory.
Is there a way to print the contents of the processes in the same command as grep? In this case, it returns two results. How do I read contents of each result?
Thanks!
Edit: I used grep -rs "*string_name*" / to look for the string
I'm guessing that the process might have ended
Correct: it was your grep process that matched.
While your grep was running, the command line file looked something like this:
grep^#-r^#string^#/^#
where the "funny" characters are NUL characters separating the arguments.
Is there a way to print the contents of the processes in the same command as grep?
From man grep, it looks like adding -a to the command line will print binary file as if it were text (grep thinks cmdline is a binary file because it contains embedded NULs).
I am new to linux bash , i was trying to do a problem which asks to edit bash.rc file and add an alias .The alias should be able to get the space usage of all the files and folders and display it on your screen. After digging out on internet i found that command for such thing is ls -lh but along with file or folder name and disk usage it is also showing the date at which file created and other unuseful things.enter image description here
So how can remove those things so that i only get file and folder name when i execute ls -lh command.
You have the right command, you can use tools like awk and sed to parse the output.
See this topic for example:
How to get the second column from command output?
Edit
Like Benjamin W. said in the comments, the output of ls should not be parsed.
This as been discussed on the following page: https://unix.stackexchange.com/questions/128985/why-not-parse-ls
After somewhere searching finally not getting what i want.
I am working on some embedded board with linux system. And many users access it by telnet.So each user suppose copy some binary somewhere and executed like ./binary.So i can see this process running by simply ps command but from where it's running i don't know.
somewhere found that, use which command but as per my understanding(if i am not wrong) which command find only path of that binary whether it's currently executing or not.
And what if multiple users copied same binary in different path?
Also looked another solution use readlink but limited busybox binary supported in my target board. So readlink is not there.
One another solution like
file /proc/"proess id"/exe but here file command not present because of custome linux in my board which contain only limited functionality and binary.
So any other solution is there?
Try ls -l /proc/"proess id"/exe. ls utility from GNU coreutils shows links with -l option, but I don't have exact information about ls from busybox.
I didn't got the script from imapsync to rename maildir filenames to work. :-/
So what I need is:
I have a mail folder with thousands of mails. After importing those emails to my new server, the filename of the emails got the creation date as a Unix timestamp in the filename, but the creation date flag of the file is the correct receive date from the email.
ls -l for one file looks like this:
-rw-r--r-- 1 popuser popuser 1350432 2013-03-16 07:22 1363563215.M562903P29332V0000000000000802I0000000000AEA46B_527.my-domain.org,S=1350432:2,S
So what the script has to do is:
1) read the creation date/time of the file (I found the command
stat -c %y filename
does this)
2) convert the date/time from 1) to a Unix timestamp
date -d "2013-03-17 11:19:01.000000000 +0100" "+%s"
3) delete the first 10 digits (wrong timestamp) of the filename and us the the timestamp from 2) instead
4) do this for all files in a specific directory
I'm a newby in Linux scripts, can anyone help me with this script?
Thank you!
Try doing this with rename :
$ rename -n 's/^\d+/(stat($_))[9]/e' [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*
from the shell prompt. It's very useful, you can put some perl code like I does in a substitution for stat with the e modifier.
You can remove the -n (dry-run mode switch) when your tests become valids.
There are other tools with the same name which may or may not be able to do this, so be careful.
If you run the following command (linux)
$ file $(readlink -f $(type -p rename))
and you have a result like
.../rename: Perl script, ASCII text executable
and not containing:
ELF
then this seems to be the right tool =)
If not, to make it the default (usually already the case) on Debian and derivative like Ubuntu :
$ sudo update-alternatives --set rename /path/to/rename
(replace /path/to/rename to the path of your perl's rename command.
If you don't have this command, search your package manager to install it or do it manually
Last but not least, this tool was originally written by Larry Wall, the Perl's dad.
Edit
As stated here, if you have the following error :
Argument list too long
Then use find like this :
find -type f -name '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*' -print0|
xargs -0 -n1 rename -n 's/^\d+/(stat($_))[9]/e'
(try it without -n1, that should works too)