-
Notifications
You must be signed in to change notification settings - Fork 2
/
bash_data.html
290 lines (275 loc) · 17.5 KB
/
bash_data.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!DOCTYPE HTML>
<!--
Phantom by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title>Bash/Command Line</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
<noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript>
</head>
<body class="is-preload">
<!-- Wrapper -->
<div id="wrapper">
<!-- Header -->
<header id="header">
<div class="inner">
<!-- Logo -->
<a href="index.html" class="logo">
<span class="symbol"><img src="images/NeuroNestLogo.png" alt="NeuroNest Logo" /></span><span class="title">NeuroNest</span>
</a>
<!-- Nav -->
<nav>
<ul>
<li><a href="#menu">Menu</a></li>
</ul>
</nav>
</div>
</header>
<!-- Menu -->
<nav id="menu">
<h2>Menu</h2>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="resource_menu.html">Resources</a></li>
<li><a href="https://sopkoc.wixsite.com/neuronest/forum">Ask a Question</a></li>
<li><a href="https://sopkoc.wixsite.com/neuronest/about">About NeuroNest</a></li>
<li><a href="https://sopkoc.wixsite.com/neuronest/contact">Contact</a></li>
</ul>
</nav>
<!-- Main -->
<div id="main">
<div class="inner">
<h1>Bash/Command Line</h1>
<span class="image main"><img src="images/pic13.jpg" alt="" /></span>
<p>Welcome to the NeuroNest tutorial on Bash and Command Line! This tutorial will show the basics of Bash scripting, allowing beginners to master the concepts of the Bash shell on Linux. </p>
<h2>1. Introduction to Bash<h2>
<h3>What is Bash?</h3>
<p>The name Bash stands for “Bourne Again SHell,” a reference to its predecessor, the Bourne shell (sh), written by Stephen Bourne. Bash is a commonly-used command-line interface (CLI) and scripting language that allows you to efficiently execute commands, manage files, and automate tasks in Unix-like systems. A command line interface (CLI) is a text-based interface where you can input commands that interact with a computer's operating system. The command line or terminal is where you write Bash commands that the computer then executes.</p>
<ul>For more information about the history of Bash, visit <a href="https://ubuntu.com/tutorials/command-line-for-beginners#2-a-brief-history-lesson">Ubuntu's Brief History Lesson</a>.</ul>
<h3>What is a shell?</h3>
<p>A “shell” is a program that provides a way for users to interact with the computer's operating system. Specifically, a shell's primary purpose is to read commands and run other programs. Shells can be a command-line interface (CLI) or a graphical user interface (GUI). The CLI allows users to type commands to run processes and manage the system, while the GUI provides a more visual approach. Bash is one of the most commonly used Unix/Linux shells.</p>
<h3>What is Unix?</h3>
<p>Unix is a powerful operating system known for its multitasking and multiuser capabilities. It provides a command-line interface and a scripting language, which allows users to automate tasks and manage complex workflows efficiently. Bash is often the default shell in many Unix-like systems, including Linux and MacOS, and is also available on Windows through tools like Git for Windows.</p>
<p><strong> <p>This tutorial will guide you through basic and advanced commands to help you get comfortable using the command line. For more information and examples, visit our <a href="bash_commands.html">extended command line page</a>.</strong></p>
<h2>2. Accessing the Command Line</h2>
To follow along with this tutorial, you will need a running version of Linux with access to the command line. If you do not already have the shell software installed, you will need to download and install it.
<ul>
<li><p><strong>macOS:</strong> The shell application is called “Terminal,” located in Applications > Utilities, or you can search for "Terminal" using Spotlight.</p></li>
<li><p><strong>Linux:</strong> Terminal applications are usually pre-installed. You can open it from the application menu or by pressing <code>Ctrl + Alt + T</code>.</p></li>
<li><p><strong>Windows:</strong> Install <a href="https://gitforwindows.org/">git for Windows</a> to get Git Bash or use Windows Subsystem for Linux (WSL) for a more comprehensive Unix-like environment.</p></li>
</ul>
<p>For troubleshooting and installation assistance, refer to these resources: </p>
<ul>
<li><a href="https://swcarpentry.github.io/shell-novice/#install-software">Software Carpentry Installation Tutorial</a></li>
<li><a href="https://carpentries.github.io/workshop-template/install_instructions/#shell">Carpentries Workshop Installation Instructions</a></li>
</ul>
<h2>3. Getting Started</h2>
<p>To get started, open the command line. You should see a prompt, which typically ends in a <code>$</code>, but can also end with <code>#</code>, <code>></code>, <code>%</code>, or <code>>>></code>. The prompt indicates that the shell is ready for input. This prompt is also called the “command line”. It should look something like this: </p>
<pre><code>$</code></pre>
<p>Your prompt might look different. Most shell environments put your user name and the host name before the prompt symbol. For example, your prompt might look like:
<pre><code>amordy@localhost $</code></pre>
<p>The prompt is followed by a text cursor, a character (usually a flashing or solid block) that indicates the position where your typing will appear.
You can type commands into this prompt and press the <code>enter</code> or <code>return</code> key to execute them. The commands entered at the command line are sent to the computer’s operating system to do a variety of different operations, or to launch various other programs. In some of the example code, you will see file and directory names in brackets (e.g., [username]). Text in brackets should be replaced with your own names.</p>
<p>Do NOT type the prompt when typing commands. Only type the command that follows the prompt.</p>
<p>Here are some helpful tips for navigating the command window: <a href="bash_shortcuts.html">keyboard shortcuts</a></p>
<h2 id="file-structure">4. File Structure</h2>
<p>Your computer organizes data in files and folders. Files can be placed in folders, which we call <strong>directories</strong>. Basically, a directory is a location in the file system that can contain files and other directories (subdirectories), creating a 'directory tree'. It's essentially a folder where files and other folders are organized.</p>
<p>At the top of the directory tree is the <strong>root directory"</strong>, which contains all of our directories. We refer to the root directory using the forward slash <code>/</code>. Inside the root directory are several other directories, such as bin (stores built-in programs) and Users (stores each users' personal directories and files).</p>
<!---<img src="images/file-tree-1.jpg" alt="tree" style="width: 35%;" alt="folders" />---> <img src="images/file-tree-4.png" alt="tree" style="width: 35%;"/>
<p>While we are using the shell, we can only be in one directory at a time (unless multiple windows are open). This is called our <strong>current working directory</strong>. When you first start the shell, your current working directory will most likely be your home directory. This means that the files and folders in your home directory are immediately accessible to you.</p>
<p>A <strong>path</strong> is a string that specifies the location of a file or directory in the file system (e.g., <code>~/Users/[name]/Downloads</code>)</p>
<ul>
<li><p><strong>Absolute Path:</strong> Specifies the full path from the root directory. Example: <code>$ /Users/name/Desktop/subdirectory</code></p></li>
<li><p><strong>Relative Path:</strong> Specifies a path relative to the current working directory. Example: <code>$ Desktop/subdirectory</code></p></li>
<li><p><strong>Home Directory:</strong> The tilde ~ represents the home directory.
<li><p><strong>Current Directory:</strong> <code>.</code> refers to the current working directory.
<li><p><strong>Parent Directory:</strong> <code>..</code> refers to the parent directory.
</ul>
<p>Most home directories follow this path format: <code>/Users/[name]</code>. In this example, we know that the directory [name] is stored within the directory /Users because Users is in the first part of the path. In addition, we know that /Users is within the root directory (/) because its name begins with <code>/</code></p>
<h3></h3>
<p>Commands are executed through the command line. To execute a command, type it into the command line after the prompt and press <code>return</code> or <code>enter</code>.</p>
<p>To see your current working directory, we will execute the command that will <i>print the working directory</i>, <code>pwd</code>.</p>
<pre><code>$ pwd </code></pre>
<p>Directories and absolute paths (i.e. exact position in the system) are always prefixed with a /. </p>
<p>Next, to see the files <i>within</i> our curent working directory, we will execute the command that prints a <i>list</i> of the files and directories within our working directory, <code>ls</code>. Your output is a list of the files and directories within your current working directory.</p>
<pre><code>$ ls</code></pre> <h2 id="Common Commands">5. Common Commands</h3>
<table>
<thead>
<tr>
<th>Command</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Navigating Directories</strong></td>
<td></td>
</tr>
<tr>
<td><code>pwd</code></td>
<td>Print working directory path.</td>
</tr>
<tr>
<td><code>ls</code></td>
<td>List files and directories in the current directory.</td>
</tr>
<tr>
<td><code>cd</code></td>
<td>Change directory.</td>
</tr>
<tr>
<td><code>cd ~</code></td>
<td>Change directory to home directory.</td>
</tr>
<tr>
<td><code>cd ..</code></td>
<td>Move up one level in the directory tree.</td>
</tr>
<tr>
<td><code>mkdir</code></td>
<td>Make directory.</td>
</tr>
<tr>
<td><code>rmdir</code></td>
<td>Remove directory (only if empty)</td>
</tr>
<tr>
<td><strong>Working with Files</strong></td>
<td></td>
</tr>
<tr>
<td><code>cp</code></td>
<td>Copy files or directories</td>
</tr>
<tr>
<td><code>rm</code></td>
<td>Remove files or directories</td>
</tr>
<tr>
<td><code>mv</code></td>
<td>Move or rename files or directories</td>
</tr>
<tr>
<td><code>nano</code></td>
<td>Opens the specified file in the nano text editor.</td>
</tr>
<tr>
<td><code>touch</code></td>
<td>Creates an empty text file.</td>
</tr>
<tr>
<td><code>grep</code></td>
<td>Search text using patterns</td>
</tr>
<tr>
<td><code>find</code></td>
<td>Search for files in a directory hierarchy</td>
</tr>
<tr>
<td><code>echo</code></td>
<td>Display a line of text</td>
</tr>
<tr>
<td><code>cat</code></td>
<td>Display file</td>
</tr>
<tr>
<td><code>less</code></td>
<td>Display a few lines of file at a time</td>
</tr>
<tr>
<td><code>head</code></td>
<td>Display first 10 lines of file.</td>
</tr>
<tr>
<td><code>tail</code></td>
<td>Display last 10 lines of file.</td>
</tr>
<tr>
<td><code>echo $NAME</code></td>
<td>Prints the value of the variable "NAME".</td>
</tr>
<tr>
<td><strong>Command Help</strong></td>
<td></td>
</tr>
<tr>
<td><code>man command</code></td>
<td>Opens the manual for "command".</td>
</tr>
<tr>
<td><code>command --help</code></td>
<td>Displays help text for "command".</td>
</tr>
<tr>
<td><strong>Managing Workspace</strong></td>
<td></td>
</tr>
<tr>
<td><code>clear</code></td>
<td>Clears the terminal screen, keeping command history.</td>
</tr>
<tr>
<td><code>exit</code></td>
<td>Exits the terminal.</td>
</tr>
</tbody>
</table>
<p>For additional information on commands, visit our <a href="bash_commands.html">extended tutorial on command line</a>.</p>
<h2 id="unix-operating-system-capabilities">6. Unix Operating System Capabilities</h2>
<h3> Bash Comnand Line and Scripting Tutorial </h3>
<p> Please visit for a<a href="bash-tutorial.html"> step-by-step tutorial with an fMRI dataset </a>i</p>
<h3 id="shell-scripting">Shell Scripting</h2>
<p>Shell scripting is a very useful tool for automating tasks. To learn more, visit the <a href="shell_scripting.html">Shell Scripting</a> page.</p>
<h3 id="permissions">Permissions</h2>
<p>To learn more about file/directory permissions and how to change them, please visit the <a href="permissions.html">Permissions</a> page.</p>
<h3 id="secure-shell">Secure Shell</h2>
<p>Please visit the <a href="ssh_info.html">Secure Shell</a> page for more information.</p>
<h3 id="version-control-with-git-and-github">Version Control with Git and GitHub</h3>
<p>Bash can be used to access and interact with Git (version control). To get started with Git, GitHub, and version control, see our <a href="git_dock_data.html">Github & Doctor page</a> and explore this resource on <a href="https://neuroimaging-data-science.org/content/002-datasci-toolbox/002-git.html?highlight=unix">version control</a>.</p>
<h3 id="working-with-virtual-environments-and-containers">Working with Virtual Environments and Containers</h3>
<ul>Here are some resources for working with virtual enviornments and containerization:
<li><a href="docker_data.html">NeuroNest's Docker tutorial</a></li>
<li><a href="https://neuroimaging-data-science.org/content/002-datasci-toolbox/003-docker.html?highlight=unix">Neuroimaging and Data Science's tutorial</a> on computational environments and computational containers.</li>
<li><a href="https://www.earthdatascience.org/workshops/setup-earth-analytics-python/setup-git-bash-conda/">Earth Lab's git, bash, and conda setup instructions</a>.</li>
</ul>
<h2 id="suggested-tutorials">7. Suggested Tutorials</h2>
<p>For an in-depth tutorial on how to use the command shell, visit <a href="https://swcarpentry.github.io/shell-novice/index.html">Software Carpentry's "The Unix Shell"</a>.</p>
<p>Another great resource is <a href="https://andysbrainbook.readthedocs.io/en/latest/unix/Unix_Intro.html">Andy's Brain Book Unix for Neuroimagers</a>.</p>
<p>Here is a tutorial with <a href="https://carpentries-incubator.github.io/shell-extras/">Software Carpentry's Extra Unix Shell Material</a>.</p>
</div>
</div>
<!-- Footer -->
<footer id="footer">
<div class="inner">
<section>
<h2>Funding</h2>
<p> We would like to express our heartfelt gratitude to <strong>Neurohackademy</strong> at the <strong>University of Washington eScience Institute</strong> for providing invaluable training and support. This experience has significantly enriched our understanding of neuroimaging and data science. We also acknowledge the support of the National Institute of Mental Health (NIMH) grant number <strong>5R25MH112480-08</strong>, which made this opportunity possible.</p>
</section>
<section>
<h2>Follow</h2>
<ul class="icons">
<li><a href="https://x.com/Neuro_Nest" class="icon brands style2 fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="https://github.com/NeuroHackademy2024/NeuroNest" class="icon brands style2 fa-github"><span class="label">GitHub</span></a></li>
<li><a href="https://sopkoc.wixsite.com/neuronest/contact" class="icon solid style2 fa-envelope"><span class="label">Email</span></a></li>
</ul>
</section>
<ul class="copyright">
<li>© Untitled. All rights reserved</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li>
</ul>
</div>
</footer>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/browser.min.js"></script>
<script src="assets/js/breakpoints.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>