Tag Info

Hot answers tagged

26

The tool to display inode detail for a filesystem will be filesystem specific. For the ext2, ext3, ext4 filesystems (the most common Linux filesystems), you can use debugfs, for XFS xfs_db, for ZFS zdb. For btrfs some information is available using the btrfs command. For example, to explore a directory on an ext4 filesystem (in this case / is dev/sda1): # ...


10

With zsh or bash4, you can use brace expansion for that: ls -d GLDAS_NOAH025SUBP_3H.A2003{001..006}.{0000,0600,1200,1800}.001.2015210044609.pss.grb >/dev/null Notice the brackets: {001..006} means expand to 001, 002, ... 006 {0000,0600,1200,1800} to every one of the above add 0000, 0600, 1200 and 1800. >/dev/null is to avoid the standard output of ...


9

Use script(1) to log everything sent to the terminal: $ script Script started, file is typescript $ # do your work ... $ # then exit with ^D $ exit Script done, file is typescript You can later look at the output with less: $ less -r typescript Beware that the logs will contain all control characters sent to the terminal, such as ANSI colours or ...


7

less is the wrong tool for the job. You can use cat for that: cat -n file1 >file2 Or nl: nl -ba file1 >file2 Or pr: pr -n -t -T file1 >file2 Or sed: sed '/./=' file1 | sed '/./N; s/\n/\t/' >file2 Or grep: grep -n . file1 | sed 's/:/\t/' >file2 Or awk: awk '{ $0 = NR "\t" $0 } 1' file1 >file2 Or again awk: awk '{ sub(/^/, ...


5

What does “are you root?” mean? In order to install packages systemwide (what apt-get does), it needs root privileges, since you will be creating and changing system files (root is the usual name for the *nix administrator account). The «are you root?» message is a gentle reminder that you "need to be root" in order to run apt-get install. This is the most ...


5

I'm not sure why you would want to do that. If you're concerned about security, if someone discovers your password on 1 July, they'll know it on 31 July or 15 September... To answer your question, if you want to ensure that the password update is done either at a scheduled time or when the system restarts, you want to install anacron. It can do periodic ...


5

You can use the DEBUG trap to do this. In this trap, $BASH_COMMAND contains the command last executed. trap 'echo "you tried to call the command [$BASH_COMMAND]"' DEBUG Note that, if you are executing commands as part of your prompt or $PROMPT_COMMAND, the trap will run on these as well. You can add checks to see if $BASH_COMMAND is the same as ...


5

A variation on @chaos solution (bash 4.0 or above or zsh 4.3.11 and above): for a in GL.....2003{001..365}.{00..18..6}00.001.2015210044609.pss.grb do [[ -f $a ]] || echo "$a" done or for a in {001..365}.{00..18..6} do [[ -f "GL.....2003${a}00.001.2015210044609.pss.grb" ]] || echo "$a" done to print only the missing day+hour


4

If grep is not necessary, one simple solution would be to use join for that: $ join -1 1 -2 3 <(sort file1) <(sort -k3 file2) Locus_1 3 3 Locus_40 etc_849 Locus_2 3 2 Locus_94 * Locus_3 2 3 Locus_4 Locus_50 * Explanation: join -1 1 -2 3: join the two files where in the first file the first (and only) field is used and in the second file the third ...


4

This answer checks the list of all attached block devices and iterates over them with udevadmin to check their respective ID_BUS. You can see all attached block devices in /sys/block. Here is the bash script from the linked answer that should let you know if it is a USB storage device: for device in /sys/block/* do if udevadm info --query=property ...


4

Adapting a solution from http://stackoverflow.com/a/9937241/1673337 you can use (g)awk to get: awk 'NR==FNR{a[$0]=1;next} {for(i in a){if($3~i){print;break}}}' File1 File2 which provides the given Output. While you could craft a RegEx to feed into grep to satisfy only matching on the third column, I feel using awk at this point is more understandable. ...


4

If your shell supports it (zsh, bash, some implementations of ksh), you could utilise process substitution grep <pattern> <(tail -n5 yourfile.txt) Where -n5 means get the five last lines. Similarly, grep <pattern> <(head -n5 yourfile.txt) would search through the 5 first lines of yourfile.txt. Explanation Simply speaking, the ...


4

Running apropos '^system' works for me, returning the list of man pages where either the page name itself starts with system or the one line description starts with system. For example, the output on Debian (jessie) includes: system-config-printer (1) - configure a CUPS server sigset (3) - System V signal API I know of no clean way to tell apropros to ...


4

In bash, this will delete everything in the current working directory which has the prefix ._: rm ._* If what you actually wanted to do was change their names to a form without the prefix, you can run: ls ._* | while read line do mv -- "$line" "${line:2}" done


3

n=$some_num { head -n"$(($(wc -l <in)-n))" >/dev/null grep 'match your string' } <in Unfortunately this requires reading the file entirely through w/ wc to get a line-count because it's not clear otherwise how many lines are in the file or how large $n is. That aside, this should be a very performant solution provided <in is a regular, ...


3

You're on Ubuntu, so I'll assume you're using bash. When you define a variable, you do it like this: you@ubuntu:~$ a="hello" No spaces. No dollar sign. It won't work otherwise. You use the dollar sign whenever you want to use that variable you defined: you@ubuntu:~$ echo $a hello Your third command should output the literal letter 'a': you@ubuntu:~$ ...


3

While chaos's answer is good to be used in interactive shells, this one can be used as a POSIX script, for example if you need to do this periodically and/or do it on another computers. #!/bin/sh i=0 while test "$((i+=1))" -lt 366 ; do for j in 00 06 12 18 ; do file="GLDAS_NOAH025SUBP_3H.A2003$(printf '%03d' ...


2

Here comes a memo to resize an NTFS partition using commandline with ntfsresize (from the ntfs-3g / ntfsprogs package) and fdisk, that should work for Windows XP-to-8 versions. Note that GParted does all the following for MBR/DOS as well as for EFI/GPT drives if ntfs-3g / ntfsprogs is installed. My references are at the end. OK in this scenario I have a ...


2

With bash-4.2 or above: printf '%(%F %T)T\n' 1234567890 (where %F %T is the strftime()-type format) That syntax is inspired from ksh93. In ksh93 however, the argument is taken as a date expression where various and hardly documented formats are supported. For a Unix epoch time, the syntax in ksh93 is: printf '%(%F %T)T\n' '#1234567890' ksh93 however ...


2

With zsh you could use the strftime builtin: strftime format epochtime Output the date denoted by epochtime in the format specified. e.g. zmodload zsh/datetime strftime '%A, %d %b %Y' 1234567890 Saturday, 14 Feb 2009


2

( t=$(printf \\t) ntt=[^$t]*$t ntc=[^$t,]* ### ^just makes it easy regardless of your sed version. sed -ne"s/..*/^($ntt){2}($ntc,)*&(,$ntc)*$t/p" | grep -Ef- ./File2 ) <File1 3 3 Locus_1 Locus_40 etc_849 3 2 Locus_2 Locus_94 * 2 3 Locus_3,Locus_4 Locus_50 * That will get a match for a line in File1 in the third ...


2

Using the grep -F option searches for literal strings anywhere in the current line. By definition, literal means that you cannot use regular expressions to narrow down your search to be within just field 3 (TAB delimited). You can, however, use the grep -f to read your pattern input file1 - but you do need to modify it into a list of regular expression. ...


2

A grep -P solution: regexp=$( echo -n '('; < File1 tr '\n' '|' | sed 's/|$//'; echo ')' ) grep -P "^[^\s]+\s+[^s]+\s+([^\s]*,)*$regexp" File2 Output: 3 3 Locus_1 Locus_40 etc_849 3 2 Locus_2 Locus_94 * 2 3 Locus_3,Locus_4 Locus_50 * If your File1 may contain special regexp characters, you'll need to escape them: ...


2

libvirt is great on the command line. virsh is the main interface. See https://libvirt.org/apps.html#command for the rest. What do you want to save to RAM when which system shuts down? virsh autostart vmName sets a vm to autostart.


2

I've taken a brief look at the source code. The HTML parsing and rendering code is a core part of elinks, and while it appears to be somewhat modular, it is not a separate library. It might be possible to separate it, but not without a good deal of work. If you're curious, the src/README file provides an overview of how the various parts depend on each ...


2

The apropos command searches both names and descriptions. But results could be filtered: apropos system | grep "^system"


2

If you already know the section of the manual page you want to view, you can pass that as a parameter to man. For example, to view the manual page for read in section 2: man 2 read The sections are as follows (this list taken from the manual page for man itself): Executable programs or shell commands System calls (functions provided by the kernel) ...


2

You can do that with awk and a little bit of help: $ N=8 $ awk -v start_line="$(( $(wc -l < alphabet) - N + 1 ))" 'NR>=start_line && /e/' alphabet sierra whiskey yankee $ finds all lines containing e in the last 8 lines of the phonetic alphabet.  This has the drawback that it reads the entire input file twice.


2

Why do you want to avoid pipe? If you really want to avoid pipe, then you will have to run two commands: tail -N filename > filename.tmp grep "string" filename.tmp (when N is the last number of lines)


2

Looks like you don't have a C compiler. Do this: yum install gcc gcc-c++ autoconf automake More info about installing a C compiler are here.



Only top voted, non community-wiki answers of a minimum length are eligible