Tag Info

Hot answers tagged

40

Bash only expands a ~ if it's the beginning of a word. You can see this between the following commands: $ echo -extract=~/test -extract=~/test oli@bert:~$ echo -extract ~/test -extract /home/oli/test Bash looks for standalone ~ characters and ~/ for this substitution. No other combination or quoted version will work. $HOME works because variable ...


26

Assuming the commands succeeded, /var/log/messages and /var/log/wtmp still exist but are now blank. Shell Redirection > is a redirection operator, implemented by the shell. Its syntax is: command > file This redirects command's standard output to file. file may also be a device node. If file doesn't exist, it is created as a regular file. If file ...


15

This is the classic case where shell tricks help a lot. for i in {000..199}; do cp file file-$i; done And I know it's a joke, but if you want a random _ or - separating the number from the name you can use: for i in {000..199}; do cp file file$(cat /dev/urandom | tr -dc '_-' | fold -w 1 | head -n 1 )$i; done (multiple line to help ...


15

You could do something like < file tee file-{001..200} however if the medium becomes unreadable it will not matter how many copies are on it - fundamentally backups require diversity. Note that tee writes its standard input to standard output as well as to each of the given files - for large files, or for files containing binary data or other special ...


14

cat will list the contents of a file comming after cat to standard output and the > sends it to the file messages and wtmp where > means to first remove all contents of the file and >> would mean to ADD to the current file. In this case you are using > so the file will end up being empty. Now for the kicker: /dev/null is a device that sends 'nothing' to ...


11

The meaning of the tilde In a shell, ~, the tilde, is not really a path. It is only replaced by a path, $HOME, some times. It is something like a shorthand, or abbreviation, provided by the shell. It can not be used like a path in general, the shell "expands" it to a path only in very special places. And even if it is expanded, it can be to something else ...


10

Use builtin command source (from help -m source): source - Execute commands from a file in the current shell. Example of execution mentioned in Question: pandya@pandya-desktop:~$ source ch_dir pandya@pandya-desktop:/usr$ Here you can see cd /usr is executed in current shell and hence directory of current shell changed! Hope this will help to ...


8

As already answered, these two lines are clearing the content of the /var/log/messages and /var/log/wtmp files, or are creating them in the unlikely event they do not already exist. However, they are based on a well established urban legend that gives /dev/null "paranormal" powers. It actually has none so cat /dev/null is a waste of keystrokes, time and ...


5

Just run the script with a . like this: pandya@pandya-desktop:~$ . ./ch_dir


5

> is output redirecting operator. It will redirect the output of command to file mentioned after it instead of standard output device, truncating or overwriting file's contents. for example ls -l > demo.txt. After executing this command, "demo.txt" will contain th output ls -l command. Now next thing is what is this /dev/null./dev/null is the null ...


5

This answer is partially a summary of the comments, but here it is: There is no way the code works in IDLE like it is pasted into your question: you do not call the function, and (thus) it has no argument as well. To make it run from the terminal, your code (file) should at least include: def num(b): print("Give a number ") b = b + 5 print(b) ...


5

To make a single duplicate of a file you probably know that you can use cp: cp file file-001 Now, to make more duplicates to a file, you can combine cp with xargs. In your case: echo file-{001..200} | xargs -n 1 cp file will copy file to file-001, file-002,... ,file-200. See man xargs for more info.


4

No it isn't. As you said, man sim doesn't exist. And running sim gives No command 'sim' found, but there are 23 similar ones In your example 'sim' was only used as part of a file name. 'fun-sym' could have been almost anything, it has no effect on the command. Since it is only the file you are creating, it only has to be a valid file name. All that ...


4

As always, the python truck comes late, but: make it executable, drag it over a terminal window, drag the file to copy over the terminal window and set the number of copies: script file number_ofcopies The number of leading zeros is set automatically, the files are named file_001.pdf, file_002.pdf, with the filenumbers placed before the extension. The ...


4

Long story short: Use a script. #! /bin/bash # With some window selection magic, or a sleep # if you want to do that manually. xdotool type word xdotool key Return And put the path of the script in the Exec field. Long story: According to the xdotool manpage: type Supports newlines and tabs (ASCII newline and tab). With respect to ...


3

No, there is no single command to do what you are asking. Why? This is the Unix philosophy: Write programs that do one thing and do it well. Write programs to work together.1 In this instance, the mkdir and rm commands do what you require, and work well together, since rm -r will delete the directory as well, so a subsequent mkdir will create ...


3

If your goal is to execute a one-line command that: Removes and recreates the directory ~/Desktop/foo if it already exists. Just creates the directory ~/Desktop/foo if it does not already exist. Then you can use: rm -r ~/Desktop/foo; mkdir ~/Desktop/foo ; is equivalent to a newline, but it lets you execute multiple commands on a single line (i.e., as ...


3

~ is not a path per se. It's a character that gets special treatment from the shell where ~ or ~/ means "replace with current user's home directory path". ~username means "replace with username's home directory path". Because it's not a path, it's only recognized in certain places in the command (as the first character of a new space-split token). When ...


3

Your suggestion is incorrect. Convert is available for all users. If you're converting into a PDF and you're seeing Unable to open image 'xxx.pdf', the program has tried to open xxx.pdf for writing and has been rebuffed by the Kernel because the current user can't write to that file. There are a couple of reasons: The current $USER can't write to the ...


3

You can get the default arp cache timeout by: cat /proc/sys/net/ipv4/neigh/default/gc_stale_time In my case it's 60. That means 60 seconds until the entry is removed. Every time the entry is used in the table, the timer for this entry resets to 60 seconds. Additionally you can set it by: echo 3600 >/proc/sys/net/ipv4/neigh/default/gc_stale_time Or ...


3

I don't think tr can replace sequences of characters (just single characters at a time, albeit possibly from a set) - I would try something like sed 's|</ROW>|&\n|g' source.xml > destination.xml


3

The tilde (~) is interpreted by your shell, as a short form of $HOME. Try the following commands: echo ~ HOME=foo echo ~ This should first print your real home directory and afterwards "foo", as you set $HOME` to that. The default value of $HOME comes from you system configuration. Use getent passwd to list all known users and their home ...


3

Try to change the $HOME variable , because tilde (~) is a short form of $HOME, or change your user's home directory in /etc/passwd but that's not recommended. Why you don't try to make and alias for cd /home/username/filename like this: alias documents='cd ~/Documents' Now when you type documents it will change to /home/user/Documents More info in man ...


3

For wired / wireless adapters ifconfig |grep HWaddr For bluetooth adapters: hciconfig


3

Instead of executing it with sh script.sh execute it with bash script.sh (or add #!/bin/bash as the first line to set the interpreter). The sh shell in Ubuntu is not bash, but a separate shell called dash. dash does not have as many features as bash, which makes it more efficient, but these missing features sometimes break scripts intended for bash. ...


2

An alternative to ifconfig is the ip command. You can use ip addr to list all your network interfaces with their IP and MAC addresses: ek@Ilex:~$ ip addr 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever ...


2

UEFI + Ubuntu-14.04.1-desktop-amd64 With a UEFI boot (without CSM enabled in firmware), the media boots into a GRUB menu. UEFI booting can be troublesome, some firmware has the tendency to change from UEFI to BIOS boot in between reboots. Other times the USB stick needs to be plugged in a different port after each boot for the firmware to recognize it. ...


2

You can display with the help of compgen builtin command as follows: To display all users run following command: compgen -u To display all groups run following command: compgen -g However you can also display all users by cat /etc/passwd | cut -d ":" -f 1.


2

I think you need thesetterm commands For your perticuler problem run sudo setterm -cursor off This will turn off the cursor sudo setterm -cursor on This will bring it back PLease see this manual for more setterm attributes For the strange problem of the cursor re appearing when you start the game, try starting it like this. sudo petris && ...


2

The text-based window-like interface, contained within a terminal, that you see when you run sudo dpkg-reconfigure lightdm is coded using the ncurses library. So if you want your program to provide an interface that looks like that, you can use ncurses too. Here's the ncurses project page. Here's an NCURSES Programming HOWTO. You can install some ncurses ...



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