tagged [shell]

Going to a specific line number using Less in Unix

Going to a specific line number using Less in Unix I have a file that has around million lines. I need to go to line number 320123 to check the data. How do I do that?

18 Mar at 22:13

How do I create a Bash alias?

How do I create a Bash alias? I'm on OSX and I need to put something like this, `alias blah="/usr/bin/blah"` in a config file but I don't know where the config file is.

16 Jan at 08:24

How to append one file to another in Linux from the shell?

How to append one file to another in Linux from the shell? I have two files: `file1` and `file2`. How do I append the contents of `file2` to `file1` so that contents of `file1` persist the process?

5 Apr at 11:4

Sending a mail from a linux shell script

Sending a mail from a linux shell script I want to send an email from a Linux Shell script. What is the standard command to do this and do I need to set up any special server names?

1 Mar at 14:36

UNIX export command

UNIX export command I am trying to understand the use of `export` command. I tried using `man export`, but there is no manual for this command. Can anyone please help me out understanding the use of `...

1 Oct at 21:26

Shell script to delete directories older than n days

Shell script to delete directories older than n days I have directories named as: How would I delete the directories that are older than 10 days with a bash shell script?

4 Jan at 01:9

How can I add a help method to a shell script?

How can I add a help method to a shell script? How do I check if a `-h` attribute has been passed into a shell script? I would like to display a help message when a user calls `myscript.sh -h`.

29 Mar at 15:6

Shell script variable not empty (-z option)

Shell script variable not empty (-z option) How to make sure a variable is empty with the `-z` option ? It returns the error :

19 Sep at 12:26

rsync copy over only certain types of files using include option

rsync copy over only certain types of files using include option I use the following bash script to copy only files of certain extension(in this case *.sh), however it still copies over all the files....

20 Jun at 01:9

Define an alias in fish shell

Define an alias in fish shell I would like to define some aliases in fish. Apparently it should be possible to define them in but they don't get auto loaded when I restart the shell. Any ideas?

9 Dec at 04:30

Pretty print in MongoDB shell as default

Pretty print in MongoDB shell as default Is there a way to tell Mongo to pretty print output? Currently, everything is output to a single line and it's difficult to read, especially with nested arrays...

How to specify a multi-line shell variable?

How to specify a multi-line shell variable? I have written a query: local sql - a very long string. Query is not formatted. How can I split a string into multiple lines?

15 Mar at 11:30

Case insensitive comparison of strings in shell script

Case insensitive comparison of strings in shell script The `==` operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is th...

17 Jun at 13:40

How to find the length of an array in shell?

How to find the length of an array in shell? How do I find the length of an array in shell? For example: And I want to get its length, which is 5 in this case.

12 May at 06:26

Rearrange columns using cut

Rearrange columns using cut I am having a file in the following format I want the columns to be rearranged. I tried below command > cut -f2,1 file.txt The command doesn't reorder the columns. Any idea...

27 Nov at 13:13

What is the $? (dollar question mark) variable in shell scripting?

What is the $? (dollar question mark) variable in shell scripting? I'm trying to learn shell scripting, and I need to understand someone else's code. What is the `$?` variable hold? I can't Google sea...

1 Aug at 02:43

How to add lines to end of file on Linux

How to add lines to end of file on Linux I want to add the following 2 lines: to the end of the file `vncservers` found at the directory `/etc/sysconfig/`. How can I do this?

13 Oct at 13:10

How to sort a file in-place?

How to sort a file in-place? When we use the `sort file` command, the file shows its contents in a sorted way. What if I don't want to get any output on stdout, but in the input file instead?

6 Jun at 09:51

unzip password protected zip in unix

unzip password protected zip in unix I need to create a shell script wherein I will unzip a password protected zip file. I know the password, and need to automate the unzip process. How can I achieve ...

31 Dec at 14:10

Quick-and-dirty way to ensure only one instance of a shell script is running at a time

Quick-and-dirty way to ensure only one instance of a shell script is running at a time What's a quick-and-dirty way to make sure that only one instance of a shell script is running at a given time?

22 Feb at 04:35

Unix shell script find out which directory the script file resides?

Unix shell script find out which directory the script file resides? Basically I need to run the script with paths related to the shell script file location, how can I change the current directory to t...

16 Jun at 08:31

How to use find command to find all files with extensions from list?

How to use find command to find all files with extensions from list? I need to find all image files from directory (gif, png, jpg, jpeg). How to modify this string to find not only .jpg files?

24 Oct at 10:7

Is there an interactive interpreter for C#?

Is there an interactive interpreter for C#? Sometimes it's handy to have access to your language to do quick things without starting Visual Studio and creating a new console app. Is there something li...

13 Jan at 17:13

Get just the filename from a path in a Bash script

Get just the filename from a path in a Bash script How would I get just the filename without the extension and no path? The following gives me no extension, but I still have the path attached:

22 Oct at 19:0

How can I execute a command stored in a variable?

How can I execute a command stored in a variable? What is the correct way to call some command stored in variable? Are there any differences between 1 and 2?

3 Dec at 03:21

Run a shell script with an html button

Run a shell script with an html button I want to launch a bash script when a button is pressed on a website. This is my first attempt: But no luck. Any suggestions?

4 Jun at 09:2

How to execute a Python script from the Django shell?

How to execute a Python script from the Django shell? I need to execute a Python script from the Django shell. I tried: ``` ./manage.py shell

16 Feb at 11:54

Linux: copy and create destination dir if it does not exist

Linux: copy and create destination dir if it does not exist I want a command (or probably an option to cp) that creates the destination directory if it does not exist. Example:

15 Sep at 23:13

How to convert a string to lower case in Bash

How to convert a string to lower case in Bash Is there a way in [bash](/questions/tagged/bash) to convert a string into a lower case string? For example, if I have: I want to convert it to:

8 Jun at 14:9

How to add a "open git-bash here..." context menu to the windows explorer?

How to add a "open git-bash here..." context menu to the windows explorer? How to add a context (aka right click) menu to the windows explorer that, when clicked, opens the git-bash console in the cur...

Shell command to find lines common in two files

Shell command to find lines common in two files I'm sure I once found a shell command which could print the common lines from two or more files. What is its name? It was much simpler than [diff](https...

30 Nov at 16:10

Copy folder recursively, excluding some folders

Copy folder recursively, excluding some folders I am trying to write a simple bash script that will copy the entire contents of a folder including hidden files and folders into another folder, but I w...

3 Feb at 16:39

Why do people write #!/usr/bin/env python on the first line of a Python script?

Why do people write #!/usr/bin/env python on the first line of a Python script? I see these at the top of Python files: It seems to me that the files run the same without that line.

20 Oct at 08:56

How to only get file name with Linux 'find'?

How to only get file name with Linux 'find'? I'm using find to all files in directory, so I get a list of paths. However, I need only file names. i.e. I get `./dir1/dir2/file.txt` and I want to get `f...

7 Dec at 10:18

Unzip All Files In A Directory

Unzip All Files In A Directory I have a directory of ZIP files (created on a Windows machine). I can manually unzip them using `unzip filename`, but how can I unzip all the ZIP files in the current fo...

22 Dec at 17:30

How to retrieve absolute path given relative

How to retrieve absolute path given relative Is there a command to retrieve the absolute path given a relative path? For example I want $line to contain the absolute path of each file in dir `./etc/`

24 May at 13:13

Check if a file exists with a wildcard in a shell script

Check if a file exists with a wildcard in a shell script I'm trying to check if a file exists, but with a wildcard. Here is my example: I have also tried it without the double quotes.

7 Oct at 10:3

How to call a function in shell Scripting?

How to call a function in shell Scripting? I have a shell script which conditionally calls a function. For Example:- Please let me know how to accomplish this.

28 Sep at 19:2

How to convert string to integer in UNIX shelll

How to convert string to integer in UNIX shelll I have `d1="11"` and `d2="07"`. I want to convert `d1` and `d2` to integers and perform `d1-d2`. How do I do this in UNIX? `d1 - d2` currently returns `...

15 Jul at 12:22

How to comment out particular lines in a shell script

How to comment out particular lines in a shell script Can anyone suggest how to comment particular lines in the shell script other than `#`? Suppose I want to comment five lines. Instead of adding `#`...

26 Mar at 13:57

Round a divided number in Bash

Round a divided number in Bash How would I round the result from two divided numbers, e.g. As when I do $testOne contains "1" when it should have rounded up to "2" as the answer from 3/2=1.5

24 Jan at 11:58

Checking for the correct number of arguments

Checking for the correct number of arguments How do i check for the correct number of arguments (one argument). If somebody tries to invoke the script without passing in the correct number of argument...

3 Dec at 01:12

Convert line endings

Convert line endings I have been using `d2u` to convert line endings. After installing Puppy Linux I noticed that it does not come with `d2u`, but `dos2unix`. Then I noticed that Ubuntu is missing bot...

22 May at 20:59

What does " 2>&1 " mean?

What does " 2>&1 " mean? To combine `stderr` and `stdout` into the `stdout` stream, we append this to a command: e.g. to see the first few errors from compiling `g++ main.cpp`: What does `2>&1` mean, ...

10 Aug at 19:30

Get current directory or folder name (without the full path)

Get current directory or folder name (without the full path) How could I retrieve the current working directory/folder name in a bash script, or even better, just a terminal command. `pwd` gives the f...

4 Nov at 08:18

While loop to test if a file exists in bash

While loop to test if a file exists in bash I'm working on a shell script that does certain changes on a txt file only if it does exist, however this test loop doesn't work, I wonder why? Thank you!

4 Mar at 14:9

find without recursion

find without recursion Is it possible to use the `find` command in some way that it will not recurse into the sub-directories? For example, And the result of something like `find DirsRoot --do-not-rec...

21 Oct at 15:18

Check existence of input argument in a Bash shell script

Check existence of input argument in a Bash shell script I need to check the existence of an input argument. I have the following script I get How do I check the input argument1 first to see if it exi...

30 May at 11:25

What does the line "#!/bin/sh" mean in a UNIX shell script?

What does the line "#!/bin/sh" mean in a UNIX shell script? I was going through some shell script tutorials and found the following sample program: Can anyone please tell me what the significance of t...

10 Nov at 18:10

Which terminal command to get just IP address and nothing else?

Which terminal command to get just IP address and nothing else? I'm trying to use just the IP address (inet) as a parameter in a script I wrote. Is there an easy way in a unix terminal to get just the...

18 Aug at 13:54